Reputation: 313
I am trying to search using dynamic finders by two fields which are status
and OpenOn(date)
. This query is working well and fine:
render(view:'list', model:[incidentInstanceList:Incident.findAllByStatusIlikeAndOpenOnGreaterThan("closed",new Date()-1,[sort:"id",order:"desc"])])
But now I'm trying to search with dynamic finders by three fields, i.e. UserId
,status
and OpenOn(date)
:
render(view:'list', model:[incidentInstanceList:Incident.findAllByStatusIlikeuserIdIlikeAndOpenOnGreaterThan("closed","${session.user.userId}",new Date()-1,[sort:"id",order:"desc"])])
This query does not work properly and shows an error:
No signature of method: app.Incident.findAllByStatusIlikeuserIdIlikeAndOpenOnGreaterThan() is applicable for argument types: (java.lang.String, org.codehaus.groovy.runtime.GStringImpl, java.util.Date, java.util.LinkedHashMap) values: [closed, tt10004, Wed Aug 24 15:12:21 IST 2011, [sort:id, order:desc]] Possible solutions: findAllByStatusIlikeuserIdIlikeAndCreatedOnGreaterThan(java.util.List)
Please guide me to solve this problem.
Upvotes: 2
Views: 2320
Reputation: 313
def incidentInstanceList = {
def criteria = Incident.createCriteria()
def results = criteria {
and {
user {
like('userId', "${session.user.userId}").toString()
}
like('status', "Closed" )
gt('closedOn',new Date()-1)
sort("id", "desc")
}
}
render(view:'list', model:[ incidentInstanceList: results, incidentInstanceTotal: Incident.count()])
}
Upvotes: 7
Reputation: 1761
Probably something like this, which, by the way, seems more legible for me:
def incidentInstanceList =
Incident.createCriteria().list
{
eq(status, 'closed')
ilike(userId, "${session.user.userId}")
gt(openOn, new Date()-1)
sort("id", "desc")
}
Upvotes: 1
Reputation: 45
Besides i think there is no need to put second parameter "" just do session.user.userId (i assume u don`t need userId to be String here) createCriteria is what u need :)
Upvotes: 0
Reputation: 7926
At the moment, you can only use dynamic finders with a maximum of two criteria. If you need to use more, you should consider using either Criteria or the HQL.
This answer goes into more detail on your question.
Upvotes: 4