我在一个名为 Events 的模型中定义了一些范围。现在我需要使用 OR 运算符加入他们。我正在使用 Rails3,我对 ActiveRelation & Arel 以及我应该如何以及如何使用它有点困惑
scope :issues, where(:subject_type => "Issue")
scope :for_company, lambda {|company| joins(:user)
.where(:users => { :company_id => company.id })
.includes(:user)}
我如何获得事件
for_company(x) OR issues
当我尝试时Events.for_company(X).or(issues)
出现错误
Events.for_company(Company.find(1)).or(Events.issues)
NoMethodError:#ActiveRecord::Relation 的未定义方法“或”
使用Events.for_company(Company.find(1)).arel.or(Events.issues)
我得到
NoMethodError:#Arel::SelectManager 的未定义方法“或”
我想获取所有问题或用户来自确定公司的事件。
select * from events
join users
on events.user_id = users.id
where users.company_id = 1
or events.subject_type = "Issues"
谢谢。