help - orm/criteria in latest coldbox

ok so I have the following setup

var c = service.newCriteria();
var items = c.createAlias( “applications”, “apps” )
.isEq(‘apps.ID’,1)
.or(
c.restrictions.ilike(‘keywords’,’%’ & event.getValue(‘q’,’’) & ‘%’)
)
.list();

this returns about 20 results and works perfectly.

However I want to dynamically append c.restrictions to the or() statement. How do I do that dynamically?

Is there an appendOR command before I call the list()? if so, how do I do that?

Jeremy R. DeYoung
615.261.8201jeremy.deyoung@lunarfly.comLunarFly.com

I should add - right now the RC[‘q’] works if its a single word however if its a multiple word string it returns no results. What I want to do is break-up the q search term on spaces and append them to the “OR” in restrictions. How can this be done?

There are two ways that I’ve been able to get it to work in my code.

The first way is better, by far, and uses disjunction():

`

c = newCriteria();

// create a dynamic array of search terms…this example isn’t dynamic, but you get the idea :wink:
var TheOrArray =[
c.restrictions.iLike( ‘keywords’, ‘%’ & event.getValue( ‘q’, ‘’ ) & ‘%’ ),
c.restrictions.iLike( ‘keywords’, ‘%’ & event.getValue( ‘q’, ‘’ ) & ‘%’ ),
…more here if you need them
];
c.disjunction( TheOrArray );

`

The second is really ugly, but works.

If you look at the source for or(), it simply takes N arguments. So, you could create a structure to pass as argumentsCollection to or():

`

c = newCriteria();

//build or() structure…easy to make this dynamic…
var TheOR={
“foo” = c.restrictions.ilike(‘keywords’,’%’ & event.getValue(‘q’,’’) & ‘%’),
“bar” = c.restrictions.ilike(‘keywords’,’%’ & event.getValue(‘q’,’’) & ‘%’),

};

c.or( argumentCollection=TheOr );

`

There may be other ways to do it, but this worked for me.

Darn, I was just typing up the disjunction, that is how I have done it.

Nice answer Joel.

Curt Gratz

so perfect - worked … well perfectly THANKS!!!

Sure thing, glad it’s working!