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

Ortus June 2024 Newsletter!

Ortus June 2024 Newsletter!

Welcome to the latest edition of the Ortus Newsletter! This month, we're excited to bring you highlights from our sessions at CFCamp and Open South Code, as well as a sneak peek into our upcoming events. Discover the latest developments in BoxLang, our dynamic new JVM language, and catch up on all the insightful presentations by our expert team. Let's dive in!

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang June 2024 Newsletter!

BoxLang June 2024 Newsletter!

We're thrilled to bring you the latest updates and exciting developments from the world of BoxLang. This month, we're diving into the newest beta release, introducing a new podcast series, showcasing innovative integrations, and sharing insights from recent events. Whether you're a seasoned developer or just getting started, there's something here for everyone to explore and enjoy.

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang 1.0.0 Beta 3 Launched

BoxLang 1.0.0 Beta 3 Launched

We are thrilled to announce the release of BoxLang 1.0.0-Beta 3! This latest beta version is packed with exciting new features and essential bug fixes, including robust encryption functionality, enhanced Java interoperability, and more efficient event handling. Key highlights include the introduction of query caching capabilities, seamless coercion of Java Single Abstract Method (SAM) interfaces from BoxLang functions, and support for virtual thread executors. So, let’s dive into the details of what’s new in BoxLang 1.0.0-Beta 3 and how you can start leveraging these updates today!

Luis Majano
Luis Majano
June 28, 2024