I have a domain object (Cat) like this:
class Cat {
String name
static hasMany = [
nicknames: String
]
}
(A cat has a name, and also has many nicknames (which are Strings))
And I am trying to query all the cats with certain nicknames.
I've tried this:
PagedResultList getCatsByNickname(String nickname, Map params) {
PagedResultList results = Cat.createCriteria().list(params) {
'ilike'('nicknames','%'+nickname+'%')
}
return results
}
But it never returns any results. (If I change the query to just use the simple name attribute, it works finding all cats with that name, but I want to query against the nicknames.)
I also tried this:
PagedResultList getCatsByNickname(String nickname, Map params) {
PagedResultList results = Cat.createCriteria().list(params) {
'nicknames' {
'ilike'('nicknames','%'+nickname+'%')
}
}
return results
}
But I get the error: org.hibernate.MappingException: collection was not an association: example.Cat.nicknames
So the question is, how do I query against a hasMany of type String?