{"id":8572,"date":"2012-09-25T13:15:34","date_gmt":"2012-09-25T07:45:34","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8572"},"modified":"2012-09-25T13:15:34","modified_gmt":"2012-09-25T07:45:34","slug":"querying-domain-class-with-hasmany-string-type","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/querying-domain-class-with-hasmany-string-type\/","title":{"rendered":"Querying Domain class with hasMany String Type"},"content":{"rendered":"<p>In my recent project there was a use case where I had to query domain&#8217;s  hasMany but relationship was not with any domain class but rather String type.<\/p>\n<p>Consider example<br \/>\n[java]<br \/>\nclass Blog {<\/p>\n<p>static hasMany = [tags: String]<\/p>\n<p>}<br \/>\n[\/java]<\/p>\n<p>Now to find all the blogs with tag &#8220;grails&#8221; , our normal way of querying hasMany relationships will not work in this scenario. In this scenario hql can be usefull:<br \/>\n[java]<br \/>\nBlog.findAll(&quot;from Blog b where :tag in elements(b.tags)&quot;, [tag: &quot;grails&quot;])<br \/>\n[\/java]<\/p>\n<p>This will return you all the blogs with  &#8220;grails&#8221;  tag.<\/p>\n<p>Hope this helps.<\/p>\n<p>Puneet<br \/>\npuneet@intelligrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my recent project there was a use case where I had to query domain&#8217;s hasMany but relationship was not with any domain class but rather String type. Consider example [java] class Blog { static hasMany = [tags: String] } [\/java] Now to find all the blogs with tag &#8220;grails&#8221; , our normal way of [&hellip;]<\/p>\n","protected":false},"author":57,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[7],"tags":[266,666,668],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8572"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/57"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=8572"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8572\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}