2015-04-03 78 views
3

下个createCriteria多个项目不用于搜索多个标签工作:中的hasMany关系

def tags = "1,2,3".split(",") 

def results = Item.createCriteria().list() { 
    itemTags { 
    and { 
     tags.each { tag -> 
     like("name", tag) 
     } 
    } 
    } 
} 

但它似乎工作,如果我改变

编辑:在我调试,我发现的标准是:

(itemTags_alias1.name=1 and itemTags_alias1.name=2 and itemTags_alias1.name=3) 

这是不是我的目标来完成。我想检查一个项目是否有全部三个标签。

回答

0

我不知道你是否能有这种情况下的标准,但你应该能够类似HQL写下面

Item.executeQuery("select i from Item i join i.itemTags tags where tags.name in (:names) group by i having count(i) >= :count", [names:nameList, count: nameList.size()]) 

看到这个question - 你会得到怎样可以做到这一点的想法在SQL中,所以你可以将它转换为hql

注:以上hql查询未经测试,但会给你想法