Skip to content

Instantly share code, notes, and snippets.

@fizx
Created October 14, 2008 20:01
Show Gist options
  • Save fizx/16781 to your computer and use it in GitHub Desktop.
Save fizx/16781 to your computer and use it in GitHub Desktop.
# Allows usage of the following syntax:
# Model.find :conditions => {:field => NotNull}
class NotNullClass
def map(*a, &b)
[].map(*a, &b)
end
def empty?
true
end
end
NotNull = NotNullClass.new
module ActiveRecord
class Base
class << self
def attribute_condition_with_not_null(argument)
case argument
when NotNullClass then "IS NOT ?"
else
attribute_condition_without_not_null(argument)
end
end
alias_method_chain :attribute_condition, :not_null
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment