Blog

Quick 4.0.0 Released

Eric Peterson August 03, 2020

Spread the word

Eric Peterson

August 03, 2020

Spread the word


Share your thoughts

Quick 4.0.0 Released

Quick 4.0.0 was released this past week and brought with it some welcome quality-of-life improvements, a handy new counts feature, improvements to error messages, and a bunch of squashed bugs. Although it is technically a major version change, most users will be able to upgrade with no changes to their code. Let's dive in to see what's new.

You can also explore these new features and improvements in a new video series on CFCasts!

What's New

Automatic OR constraint scoping.

If you've read the qb 8.0.0 release post, this one will sound familiar to you — scopes, whereHas, and whereDoesntHave all automatically scope any OR constraints added inside them. The rationale here is the same — it was very easy to miss scoping OR constraints inside a scope or whereHas callback because you were already in a separate function. whereHas even has where in the name, adding to the confusion! In Quick 4.0.0, all of these cases will be automatically scoped. I am personally very excited for this feature as I have spent a lot of time trying to track down errors like these in the past.

Relationship Counts

Subselects are already easy to add in Quick thanks to using the existing relationship definitions. In Quick 4.0.0, adding the count of a relationship as a subselect is even easier using the withCount method. By default, you will access the returned count using the relationship name appended with Count, i.e. comments will be available under commentsCount.

var post = getInstance( "Post" )
	.withCount( "comments" )
	.findOrFail( 1 );
	
post.getCommentsCount();

You can alias the count attribute using the AS syntax as follows:

var post = getInstance( "Post" )
	.withCount( "comments AS myCommentsCount" )
	.findOrFail( 1 );
	
post.getMyCommentsCount();

This is especially useful as you can dynamically constrain counts at runtime using the same struct syntax as eager loading with the with function.

var post = getInstance( "Post" )
	.withCount( [
	    "comments AS allCommentsCount",
	    { "comments AS pendingCommentsCount": function( q ) {
	        q.where( "approved", 0 );
	    } },
	    { "comments AS approvedCommentsCount": function( q ) {
	        q.where( "approved", 1 );
	    } }
	] )
	.findOrFail( 1 );

post.getAllCommentsCount();	
post.getPendingCommentsCount();
post.getApprovedCommentsCount();

Improved belongsToMany relationships setter error message

Quick now warns you when you try to save records to a belongsToMany (many-to-many) relationship before saving the entity. Before this would fail when trying to execute the query inserting records into the pivot table and was a bit obscure. Now you will get a helpful error message explaining the problem and a potential solution.

Wrap Up

That's the new features in Quick 4.0.0. Again, while it is technically a breaking change, I like to think of this more as Quick 3.2.0. Don't let the major version number scare you and start using that new Quick goodness!

Add Your Comment

Recent Entries

BoxLang 1.0.0 Beta 7 Launched

BoxLang 1.0.0 Beta 7 Launched

We are pleased to announce the release of BoxLang 1.0.0-Beta 7! This latest beta version includes improvements and essential bug fixes, but more importantly it certifies the execution of ColdBox HMVC and TestBox.

What is BoxLang?

BoxLang is a modern dynamic JVM language that can be deployed on multiple runtimes: operating system (Windows/Mac/*nix/Embedded), web server, lambda, iOS, android, web assembly, and more. BoxLang combines many features from different progr

Luis Majano
Luis Majano
July 26, 2024
New BoxLang Feature: Java Method References and Higher-Order Functions

New BoxLang Feature: Java Method References and Higher-Order Functions

We’ve added more goodies to our BoxLang Java interop: method references and higher-order functions. CFML has never let you do these things, making Java Interop feel like a second-class citizen. But with BoxLang, we’re elevating Java integration to a new level.

Maria Jose Herrera
Maria Jose Herrera
July 26, 2024
Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Level Up Your ColdFusion Skills with our Virtual Live Training: ColdBox from Zero to Hero

Are you a CFML developer looking to take your skills to the next level? Look no further than the ColdBox from Zero to Hero Virtual Live Training! This intensive two-day course will equip you with the knowledge and expertise to build robust and scalable applications using ColdBox 7, the latest version of the most popular CFML MVC framework.

What You'll Learn:

  • Master the Fun...

Cristobal Escobar
Cristobal Escobar
July 24, 2024