Reputation: 33591
We have a search page on a grails application. This page needs to be able to dynamically build queries based on a number of properties.
For example:
If this were a Java application I would use the hibernate criteria API. One problem with the criteria API is it makes arbitrary joins impossible.
So is there a way to dynamically build queries like this? If the criteria API in GORM can be dynamically modified that could work, or I could use a totally different approach.
Upvotes: 0
Views: 417
Reputation: 50275
Seems like a similar question from you was answered by @dmahapatro few months back. Your present scenario would look something like:
def user = User.createCriteria().list{
if(params.email != null){
or{
eq('email', params.email)
iLike('email', "%${params.email}%")
}
} else if(params.id != null){
idEq(params.id)
} else if(params.name != null){
eq('name', params.name)
} else if(params.memberOf != null){ //This can be optimized
groups{
eq('name', params.memberOf)
}
}
}
Is this what you were looking for?
Upvotes: 2