[Tip of the Week] Using Dynamic Finders with ORM

Dynamic Finders are brand new to ColdBox 3.5.3 which will be released shortly. I usually give tips on released functionality, but we’re real excited about our new Grails-inspired functionality and invite you to check it out on our development line to give them a spin.

Dynamic Finders basically let you create very readable code with dynamic method names that describe the criteria being used to to load or count ORM entities. The best part is, you don’t have to write any of the code-- just call the dynamic method and ColdBox does the rest!

Any ColdFusion ORM entity that extends our ActiveEntity component as well as any base or virtual entity service will all support these dynamic finder methods. Each method must start with “findBy”, “findAllBy”, or “countBy” and can contain any number of properties and conditionals.

Here’s some examples:

user = entityNew(“User”).findByLastName(“Majano”);
users = entityNew(“User”).findAllByLastNameLike(“Ma%”);

property name=“userService” inject=“entityservice:userService”;
users = userService.findAllByLastLoginBetween( “01/01/2010”, “01/01/2012” );
users = userService.findAllByLastLoginGreaterThan( “01/01/2010” );
count = userService.countByLastLoginGreaterThanAndLastNameLike( “01/01/2010”, “jo%”);

Super easy, right? Download the bleeding edge now to play with them! (https://github.com/ColdBox/coldbox-platform/zipball/development)

More info here: http://wiki.coldbox.org/wiki/WhatsNew:3.5.3.cfm
Here’s a quick demo from today’s ColdBox Connection meeting: http://experts.adobeconnect.com/p6byoxrm7aa/

P.S. You can still have control over things such as your query’s maxResults and offset by passing a struct of settings in as the last parameter to your dynamic method.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

WOW very nice. I love ORM and now I’ve started using ColdBox you guys are just making using it amazing.

Since coming to all things ‘Box’ a few months ago, I truly have been converted and I’m just blown away by all the learning material and the speed at which new features appear.

Great stuff.

Richard

Brad, is it possible to post these tips of the week in a way that can be filtered and accessed via RSS feed? It would be nice to have a way to extract them from the rest of the posts.

Thanks,

Cristian