次のような非常に複雑なクエリがあります。
@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")
次に、2 つの日付の間に作成されたもの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
関連付けの句にパラメーターを渡す可能性はありますか?