【发布时间】:2015-11-27 01:49:53
【问题描述】:
我想使用 '.includes()' 有效地获得结果。
我需要包含表来检索不为零的记录。我需要在查询中保留 included: true。
使用 postgres。
角色有很多任务。
任务属于一个角色。
以下方法有效,但从 Roles 表中获取了错误的记录。
Task.includes(:role).where(included: true, roles: {doer: nil})
下一部分是我想要的想法...... 但显然 where 子句的“角色”值语法错误。
Task.includes(:role).where(
included: true,
roles: {
doer != nil #=> where 'doer' is not 'nil'
})
我正在寻找一个有效的查询,这就是我进行包含的原因。 如果没有多个 where 查询,我不知道如何获得它。
如果您理解这个问题,但认为可以问得更清楚一些,请告诉我。除非使用了多个 where 语句,否则我在任何地方都找不到这个答案的任何线索。
【问题讨论】:
标签: ruby-on-rails activerecord null include where