In my recent project there was a use case where I had to query domain’s hasMany but relationship was not with any domain class but rather String type.
Consider example
class Blog {
static hasMany = [tags: String]
}
Now to find all the blogs with tag “grails” , our normal way of querying hasMany relationships will not work in this scenario. In this scenario hql can be usefull:
Blog.findAll("from Blog b where :tag in elements(b.tags)", [tag: "grails"])
This will return you all the blogs with “grails” tag.
Hope this helps.
Puneet
puneet@intelligrape.com
