【发布时间】:2015-03-17 12:18:28
【问题描述】:
我希望能够编写一个条件,让我可以搜索所有具有特定 DevelopmentOfInterest(hasMany) 或根本没有的潜在客户。
我的领域模型看起来像这样:
Lead {
Set<Development> developmentsOfInterest
static hasMany = [
developmentsOfInterest:Development
]
}
如果我根据开发列表搜索特定列表,我可以在我的条件中使用以下内容:
developmentsOfInterest{
'in'("id", developments*.id)
}
为了找到所有没有任何进展的人,我使用 isEmpty
isEmpty("developmentsOfInterest")
所以逻辑告诉我,如果我将这两个放在一个 OR 中,我会得到组合列表..
or{
isEmpty("developmentsOfInterest")
developmentsOfInterest {
'in'("id", developments*.id)
}
}
它不会..它只会返回感兴趣的列表(基本上忽略了“isEmpty”)
生成的sql如下
where (this_.account_id=? and (not exists (select 1 from lead_development where this_.id=lead_developments_of_interest_id) or (developmen1_.id in (?, ?))))
但我认为这将是正确的 sql 命令?正确读取:
(not exists (select 1 from lead_development where this_.id=lead_developments_of_interest_id) or (developmen1_.id in (?, ?))
更新: 我比较了 isEmpty() 或 sizeEq() 生成的 SQL,以及“in”,“in”添加了一大堆带连接的额外查询代码。 我猜测连接不正确,这导致 isEmpty 不起作用(因为它只会显示与 developmentOfInterests 连接的项目)
where (this_.account_id=? and (? = (select count(*) from lead_development where this_.id=lead_developments_of_interest_id) or this_.id in (?))) order by lower(this_1_.first_name) asc limit ?
Account_id 部分的过滤条件进一步向上。 任何人都可以帮忙吗? 问候,
【问题讨论】: