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

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023