Question

I have a domain class User with all the instances like

[User : 1, User: 2, User : 3, User:4, User: 5, User: 6, User: 7, ...]

and an instance list userInstanceList with only a few objects, say

[User : 3, User:4]

My search term is in User : 4 and also in some other objects in User. When I search using

User.search(userInstanceList, searchTerm)

it returns all the objects in User with the searchTerm. How can I search objects only in userInstanceList

Was it helpful?

Solution

If you want to restrict the search to only the things in the userInstanceList, you should be able to just use the in clause when searching.

User.findAll { 
   searchTerm && id in userInstanceList*.id
}

or

User.withCriteria {
    searchTerm
    inList id, userInstanceList*.id
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top