i am trying to get a pagedResultList using chained named queries, but i seem to fail. Any hints or tips on how this can be achieved?
See modified example below from the Grails documentation that should illustrate my needs
def books = Publication.recentPublications.grailsInTitle.list(params) {
or {
like 'author', 'Tony%'
like 'author', 'Phil%'
}
}
This always returns an ArrayList..
When or remove the additional criteria and use it like below it works
def books = Publication.recentPublications.grailsInTitle.list(params)
I would like to add some criteria closures, any hints or tips on how i could achieve this?
I am facing same problems with named queries. This is my solution applied to your classes. Comment if it works for you.
class Publication {
//fields, constraints, etc.
namedQueries = {
authoredLike { String authorName ->
if (authorName) {
like 'author', authorName
}
// untested, but you get the point, please experiment
authoredLikeMany { List<String> authors ->
authors.each { String authorName -> like 'author', authorName }
}
}
}
def tonyBooks = Publication.recentPublications.grailsInTitle.authoredLike('Tony%').list(params)
def tonyAndPhilBooks = Publication.recentPublications.grailsInTitle.authoredLikeMany(['Tony%', 'Phil%']).list(params)