我有這樣一個龐大複雜的查詢:任何可能的方法來添加ON子句的參數包括在鋼軌上的左連接?
@objects = Object.joins({ x: :y }).includes(
[:s, { x: { y: :z } }, { l: :m },:q, :w,
{ important_thing:
[:h, :v, :c,:l, :b, { :k [:u, :a] }]
}
]).where(conditions).order("x.foo, x.bar")
然後我想告訴所有Objects
,只在兩個日期之間創建Important_things
。
如果我把這個放在那裏where
條款我沒有得到所有Objects
,只有Objects
有知情日期之間Important_things
。
使用原始SQL中的解決方案是這樣的:
select * from objects left join important_things on important_things.object_id = objets.id and important_things.created_at between 'x' and 'y'
相反的:
select * from objects left join important_things on important_things.object_id = objets.id where important_things.created_at between 'x' and 'y'
我真的需要所有這些對象,我不希望使用原始的SQL ,任何解決方法或將參數傳遞給ON
子句的可能性?
我知道這一點,但我不想寫所有我需要的連接:\ – 2013-03-18 18:40:25
另外,我失去了之前完成的所有熱切加載...... – 2013-03-18 19:11:22