【发布时间】:2015-10-13 13:03:25
【问题描述】:
我在我正在从事的项目中使用以下方法进行多重连接。我不明白这里发生了什么 |操作员。任何解释将不胜感激。
class SampleUnit < ActiveRecord::Base
def unit_code(code)
joins(table_a: [:table_b]).
eager_load(table_a: [:table_b]).
eager_load(:table_c).
eager_load(:table_d).
eager_load(:table_e).
where(‘table_b.code like ?', code) |
eager_load(table_a: [: table_b]).
eager_load(: table_c).
eager_load(: table_d).
eager_load(: table_e).
where('sample_units.code like ?',(code))
end
end
【问题讨论】:
-
我没有使用 ruby 或 activerecord 的经验,但这似乎只是
WHERE子句中的OR条件。 -
这没有多大意义。
OR的左边部分总是真实的(意思是,右边部分永远不会被评估) -
另外,您是重新输入代码还是复制/粘贴?你有一个反引号而不是引号。
-
我完全错了。检查更新的答案:)
标签: ruby-on-rails join rails-activerecord