Is it possible to do an "OR" on two ActiveRecord scopes using MetaWhere?

132 Views Asked by At

Is it possible to do an "OR" on two scopes?

For example, consider a simple example where I have a class User with 2 scopes - professors and lecturers

Then, can I re-use the 2 scopes to get users who may be either professors or lecturers? Some thing like User.professors.or.lecturers

1

There are 1 best solutions below

0
On

Metawhere allows you write conditions inside scopes as a Ruby statements it doesn't have any influence on scopes. Since (and unfortunately) in Rails scopes are joined (AFAIK) using only AND you can't achieve what you want. Possible solution of the problem is new scope proffesors_or_lecturers also check this question