ORM Criteria - Grouping AND and OR

Guys,

I am trying to build a query with the following criteria model … ( username = X OR email = X ) AND active = true.

My code looks like this:

var criteria = UserService.newCriteria();
var User = criteria.and(
criteria.or(
criteria.restrictions.eq( “username”, lcase( trim( arguments.username ) ) ),
criteria.restrictions.eq( “email”, lcase( trim( arguments.username ) ) )
),
criteria.restrictions.eq( “active”, true )
).list();

When this executes though, I am getting an error on line 182 of \coldbox\system\orm\hibernate\criterion\Restrictions.cfc that says “The add method was not found.”

Before I go tearing apart the Restrictions.cfc object, is my use of the criteria above correct?

Thanks!

I would do this:

var c = userService.newCriteria();
c.isTrue( “active” )
.or( c.restrictions.eq( “username”, lcase( trim( arguments.username ) ) ),
c.restrictions.eq( “email”, lcase( trim( arguments.username ) ) )
).list();

However, I have seen sometimes where ACF goes cookoo when concatenating AND and OR calls, the parser just goes cookoo. You can alternatively use: $and(), and $or() as well.

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano