如何获取不在域B中使用的列表A?
域名A
Class A{
String name
String code
}
域B
Class B{
A aaa
String description
}
示例数据:
**domain A**
id+versioin+name +code+|
1 | 0 |Bobby |bob |
2 | 0 |anto |ant |
3 | 0 |Jessica|jes |
4 | 0 |hera |her |
**domain B**
id+version|a_id|description + |
1 | 0 | 1 |this is bobby |
2 | 0 | 3 |this is jessic|
如何从A中获取未在B中使用的列表。
i tried this
def b = B.list()
def c = A.createCriteria()
def results = c.list {
not { 'in'(b) }
}
但失败..
答案 0 :(得分:6)
def b = B.list()
def c = A.createCriteria()
def results = c.list {
not { 'in'("id",b*.aaa.id) }
}
答案 1 :(得分:1)
为了完整性,请注意Grails 2.4(处于RC阶段并即将进入GA),您可以使用子查询将此查询编写为单个查询,这将更好地执行:
def c = A.createCriteria()
def results = c.list {
notIn new DetachedCriteria(B).id
}