我有以下两个班级:
class Person{
String name
static hasMany = [
items: Item
]
}
class Item{
String name
}
多人也可以拥有相同的物品。我正在尝试获取其集合中具有特定项目的所有人员的列表。 I.E.人员A和B都在其列表中有项目A,因此将它们返回。不幸的是,他们没有findAllByCollectionContains(),最接近的是findAllByCollection(),这需要一个精确的集合。
我一直在尝试使用executeQuery来给我一个更多的控制权,但还没有想出任何东西。
我尝试过的例子:
Person.executeQuery("select name from Person p where ? in p.items",[item])
有什么建议吗?
答案 0 :(得分:1)
您必须加入项目集合,然后才能轻松查询
Person.executeQuery("select name from Person p join p.items as i where i = ?",[item])