Created
January 12, 2021 18:20
-
-
Save dmitry/8aa38643e44752dd728d441a2d6f83c9 to your computer and use it in GitHub Desktop.
Union scope ActiveRecord concern (allow to use multiple scopes with or)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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