Skip to content

Instantly share code, notes, and snippets.

@wakiki
wakiki / gist:3312792
Created August 10, 2012 09:12
Rails 3 merging scope with OR
# By Steve Leung
# steve@leungs.me
class ActiveRecord::Relation
# temporarily hack for allowing combining scopes with OR
# doesn't add the join tables so need to use .includes manually
# ie. Jobship.includes(:job).or(Jobship.accepted, Jobship.declined).count
def or(*scopes)
clauses = *scopes.map do |relation|