I have a domain object (Cat) like this:
class Cat {
String name
static hasMany = [
nicknames: String
]
}
(A cat has a name,
You can also use HQL (tested with Grails 2.5.0):
Cat.findAll("from Cat c inner join c.nicknames as n where upper(n) like '%'||?||'%'", [nickname.toUpperCase()])
You can use HQL for querying in such a scenario. For example,
Cat.findAll("from Cat c where :nicknames in elements(c.nicknames)", [nicknames:'kitty'])
After a lot of trying and researching, I found this will work with Grails 2.4.0, I don't know about older versions.
Cat.withCriteria {
createAlias('nicknames', 'n')
ilike 'n.elements', '%kitty%'
}
The trick is to use 'n.elements'