Last active
December 12, 2015 06:28
-
-
Save bilogub/4729079 to your computer and use it in GitHub Desktop.
Rails Null Relation
This file contains 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
# Takes relation or model as klass argument | |
# to produce empty relation | |
class NullRelation | |
class << self | |
def for(klass) | |
raise(ArgumentError, "Model class is not provided") unless klass | |
klass.where('1 = 0') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment