Skip to content

Instantly share code, notes, and snippets.

@bilogub
Last active December 12, 2015 06:28
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 bilogub/4729079 to your computer and use it in GitHub Desktop.
Save bilogub/4729079 to your computer and use it in GitHub Desktop.
Rails Null Relation
# 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