【问题标题】:OR criteria Grails nested objectsOR 条件 Grails 嵌套对象
【发布时间】:2019-08-10 08:41:14
【问题描述】:

我正在尝试在两个嵌套对象上使用带有 OR 的 createCriteria。

这是我正在使用的代码:

or {
  ordersSecondaryReceptionSystem {
    eq('code', params.receptionSystemCode)
  }
  ordersReceptionSystem {
    eq('code', params.receptionSystemCode)
  }
}

只考虑两者中的一个,即次要的。 我有什么遗漏吗?

【问题讨论】:

  • 如果不了解您的域对象的更多信息,很难确定。您可以打开日志记录以查看正在生成的确切 SQL,这通常有助于解决这类问题。

标签: grails criteria


【解决方案1】:

我可以通过创建别名来修复它:

createAlias('ordersReceptionSystem', 'ordersReceptionSystem', Criteria.LEFT_JOIN)
                    createAlias('ordersSecondaryReceptionSystem', 'ordersSecondaryReceptionSystem', Criteria.LEFT_JOIN)
                    or {
                        eq('ordersReceptionSystem.code', params.receptionSystemCode)
                        eq('ordersSecondaryReceptionSystem.code', params.receptionSystemCode)
                    }

【讨论】:

    猜你喜欢
    • 2010-12-24
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    相关资源
    最近更新 更多