personList = Person.withCriteria { if (params.firstName) eq('firstName', params.firstName).ignoreCase() if (params.lastName) eq('lastName', params.lastName).ignoreCase() if (params.login) eq('login', params.login).ignoreCase() if (params.personHashId) like('personHashId', params.personHashId) maxResults(Constants.SEARCH_MAX_RESULTS) }
Code Snippets, Ideas and Rants from a Tech Lead interested primarily in server side web development and leading teams who build web apps.
Tuesday, November 23, 2010
Case Insensitive withCriteria
I found this easy way to do a case insensitive query on the DB using with Criteria. Unfortunately Grails documentation does not mention this, but remember you are using Hibernate. So using .ignoreCase() on the eq works perfectly.
Subscribe to:
Post Comments (Atom)
Thank you dekay,just what I needed. -Bose
ReplyDeleteIs there a way to do the ignore case for the like operator as well?
ReplyDeleteSomething like,
Person.withCriteria {
or{
like('firstName', params.fname)
like('lastName', params.lname)
}
}
How do i apply the ignoreCase to the above code?