Search code examples
grailsgroovygrails-orm

Can I use multiple ilike for the same field in grails?


I have a class & I am using createCriteria to fetch the record.

DomainClass.createCriteria().list(max: max, offset: offset) {
...
        ilike("field", value.encodeAsHTML() << "%") 
        ilike("field", value << "%") 
}

So it should fetch records matching for both


Solution

  • Mutliple ilikes work just fine in a criteria. However, based on your comments it sounds like you are looking for an OR instead of an AND and you can do so like this:

    DomainClass.createCriteria().list(max: max, offset: offset) {
    ...
        or {
            ilike("field", value.encodeAsHTML() << "%") 
            ilike("field", value << "%") 
        }
    }