Merge scopes with OR

I’d be quite interested in a feature merging scopes with OR - currently the default way is AND.

The feature seems to have been requested/reported here:

A pull request was sent, but it needs some work.

I wrote a quick attempt too here:

It uses the syntax:
Jobship.includes(:job).or(Jobship.accepted, Jobship.declined).count

though it might be better like this:



It doesn’t look like it should be too hard - any reason why this isn’t included in the current ActiveRecord?

I haven’t dug too deep into ActiveRecord::Relation or Arel… but I think this is a common use case.

Anyone interested in helping me work on this further?


Hi folks.

I wrote the pull request that’s in for this.

I’m still looking for some feedback.

In particular the main issue with it is in replacing the where clauses without hosing other aspects of the scopes.

Perhaps Aaron would like to take a look at it, as I know he has done a fair bit of spelunking in arel etc.