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

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024
Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024