Rails3 & ActiveRecord::Relation - Arel and OR
I have some scopes definied in a Model called Events. Now I need join them using OR operator. I’m using Rails3 and I’m a bit confused with ActiveRelation & Arel and how and how I should use this
scope :issues, where(:subject_type => "Issue")
scope :for_company, lambda {|company| joins(:user)
.where(:users => { :company_id => company.id })
.includes(:user)}
How I can get events
for_company(x) OR issues
When I try Events.for_company(X).or(issues)
I get an error
Events.for_company(Company.find(1)).or(Events.issues)
NoMethodError: undefined method `or' for #ActiveRecord::Relation
using Events.for_company(Company.find(1)).arel.or(Events.issues)
I get
NoMethodError: undefined method `or' for #Arel::SelectManager
I w开发者_Python百科ant get all events that are issues or where user is from a determined company.
select * from events
join users
on events.user_id = users.id
where users.company_id = 1
or events.subject_type = "Issues"
Thanks.
Ruby on Rails 3 howto make 'OR' condition
Rails3: combine scope with OR
Event.for_company(Company.find(1)).issues
精彩评论