Is there any way to do cleanly in Arel and/or ActiveRecord::Relation,
the following:
-
A complex OR clause
I am aware of:
t = A.arel_table (A === model, “as” = table)
A.where(t[:colum1].lt(x).or(t[:column2].gt(y)).to_abut am looking for a case where I want to write something more
complex (multiple tables) like:some relation: r1 = A.includes(:lots of
stuff).where(…).where(…).where(…)…
r2 = A.includes(:lots of stuff).where(…).where(…)and I want r1.or.r2 , or, written: r1 | r2 …
exactly like r1.merge(r2) or r1 & r2 for an AND chain…
-
Doing a group clause on, for example, r2 above, where the grouping is
done by a specific column (e.g. :item), but the item column comes from
r1, not r2, and is linked together using another column (e.g.
:position).That is, something like (writing pseudo Arel-like code):
r2.includes(r1.results as
special_chain).where("special_chain.position ==
as.position).group(“special_chain.item”).sum
… is that possible/close?
Thanks.