Created
September 21, 2013 01:13
-
-
Save avit/6646003 to your computer and use it in GitHub Desktop.
Allow Ransack to include NULL values in "does not equal" searches.
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 Arel | |
module Predications | |
def not_eq other | |
if other.is_a? Nodes::Not | |
Nodes::Equality.new self, other.value | |
else | |
Nodes::NotEqual.new self, other | |
end | |
end | |
def eq other | |
if other.is_a? Nodes::Not | |
Nodes::NotEqual.new self, other.value | |
else | |
Nodes::Equality.new self, other | |
end | |
end | |
def matches other | |
if other.is_a? Nodes::Not | |
Nodes::DoesNotMatch.new self, other.value | |
else | |
Nodes::Matches.new self, other | |
end | |
end | |
def does_not_match other | |
if other.is_a? Nodes::Not | |
Nodes::Matches.new self, other.value | |
else | |
Nodes::DoesNotMatch.new self, other | |
end | |
end | |
end | |
end |
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
# Include NULL values in NOT queries | |
# https://github.com/ernie/ransack/issues/123 | |
module Ransack | |
module Constants | |
HACKED_PREDICATES = [ | |
['not_eq', {:arel_predicate => 'eq_any', :formatter => proc { |v| [Arel::Nodes::Not.new(v), nil] }}], | |
['does_not_match', {:arel_predicate => 'matches_any', :formatter => proc { |v| [Arel::Nodes::Not.new(v), nil] }}] | |
] | |
AREL_PREDICATES.delete('not_eq') | |
AREL_PREDICATES.delete('does_not_match') | |
DERIVED_PREDICATES.concat(HACKED_PREDICATES) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment