开发者

Grails: how can I query domain class' hasMany-relationship against intersecting set of objects?

I have about the following:

class Object_1 {
  static hasMany = [tags:Tag]
  Set tags;
  ...
}

Now I have a set of tags and want to find all Object_1-instances with intersecting (!= matching) tag开发者_开发问答s. I was thinking of something like

Object_1.findAllByTagsInList(tags);

But that does not work at all - I get a "nested exception is org.hibernate.exception.SQLGrammarException: could not execute query". I have the feeling I am missing something important. Help highly appreciated.


I actually found an elegant way to solve the problem. I redesigned the relationship to be many-to-many which allows for simply iterating over the tags list finding all the relevant objects.

... of course now I have to take care of that relationship a couple of times - but I am happy to have this working with few locs.


"in list" is not one of the operators recognized in dynamic finder methods - that won't work.

Instead, you'll have to use HQL or the criteria builder to formulate your query (and perhaps put it in a static finder method).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜