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

Mastering Events and Listeners in CBWIRE

Mastering Events and Listeners in CBWIRE

In CBWIRE, events and listeners are the backbone of building responsive, modular applications without relying heavily on JavaScript. This guide walks you through setting up and using CBWIRE events to create seamless interactions between components, from dispatching events in CFML and frontend templates to listening with Alpine.js and JavaScript. Learn how to make your applications feel dynamic and engaging by effortlessly connecting components. Whether you’re triggering events to update a dashboard or targeting specific parts of your app with dispatchTo, these techniques will empower you to create a modern, interactive CFML experience with ease.

Grant Copley
Grant Copley
November 11, 2024
10 Key Benefits of Hiring a Specialized ColdFusion Consulting Team

10 Key Benefits of Hiring a Specialized ColdFusion Consulting Team

ColdFusion remains a powerful and versatile platform for building dynamic web applications. However, keeping your ColdFusion environment optimized, secure, and scalable requires specialized expertise. Whether managing a long-standing ColdFusion application or planning new development projects, hiring a dedicated ColdFusion consulting and support team can be a game-changer for CTOs, CIOs, and developers. Here's why:

1. Expert Guidance on ColdFusion Web Development

...

Cristobal Escobar
Cristobal Escobar
November 08, 2024
ColdBox Free Tip 5 - Building Named Routes with a Struct

ColdBox Free Tip 5 - Building Named Routes with a Struct

**Did you know ColdBox provides flexible ways to build routes using structs?** In this tip, we’ll cover how to use the `event.buildLink()` and `event.route()` methods for named routes, a feature that’s especially handy when working with dynamic URLs.

Maria Jose Herrera
Maria Jose Herrera
November 07, 2024