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%");
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.
Add Your Comment