Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Union scope ActiveRecord concern (allow to use multiple scopes with or)
module UnionScopeConcern
extend ActiveSupport::Concern
class_methods do
def union_scope(*scopes)
scopes[1..-1].inject(where(id: scopes.first)) { |all, scope| all.or(where(id: scope)) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment