How to search using a domain class instance?

158 Views Asked by At

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

1

There are 1 best solutions below

2
Aaron On BEST ANSWER

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
}