Reputation: 61
String query='test'
def user = User.withCriteria {
ilike('firstName', '%'+query+'%')
or {ilike('lastName', '%'+query+'%')}
or {ilike('email', '%'+query+'%')}
}
above is the sample code i need to find those object if any one of three of these field( firstName lastName email ) contains query string thnks
Upvotes: 0
Views: 1918
Reputation: 235
You can do in this way
String query='test'
def crit = User.createCriteria()
def user = User.list{
or{
ilike('firstName', '%'+query+'%')
ilike('lastName', '%'+query+'%')
ilike('email', '%'+query+'%')
}
maxResults(1000)
order("firstName")
}
Upvotes: 0
Reputation: 4021
Try joining the conditions inside one or
or {
ilike('firstName', '%'+query+'%'),
ilike('lastName', '%'+query+'%'),
ilike('email', '%'+query+'%')
}
You can also turn on SQL debugging to see how your queries get built.
Upvotes: 1