DJ Cole
2011-Feb-02 19:08 UTC
Arel-ActiveRecord:Relation: OR clause, and correlated models help
Is there any way to do cleanly in Arel and/or ActiveRecord::Relation,
the following:
1. 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_a
but 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...
2. 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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.