Skip to content

Instantly share code, notes, and snippets.

@dmitry
Created January 12, 2021 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry/8aa38643e44752dd728d441a2d6f83c9 to your computer and use it in GitHub Desktop.
Save dmitry/8aa38643e44752dd728d441a2d6f83c9 to your computer and use it in GitHub Desktop.
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