diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/nodes.rb | 9 | ||||
-rw-r--r-- | lib/arel/nodes/node.rb | 2 | ||||
-rw-r--r-- | lib/arel/predications.rb | 28 |
3 files changed, 24 insertions, 15 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index 3642958cf8..6ce1ed7dba 100644 --- a/lib/arel/nodes.rb +++ b/lib/arel/nodes.rb @@ -62,6 +62,13 @@ module Arel end def nil?; @val.nil?; end + + def eql? other + self.class == other.class && + self.val == other.val && + self.attribute == other.attribute + end + alias :== :eql? end class Quoted < Arel::Nodes::Unary # :nodoc: @@ -69,7 +76,7 @@ module Arel def self.build_quoted other, attribute = nil case other - when Arel::Nodes::Node, Arel::Attributes::Attribute + when Arel::Nodes::Node, Arel::Attributes::Attribute, Arel::Nodes::SelectStatement, Arel::Table, Arel::Nodes::BindParam other else case attribute diff --git a/lib/arel/nodes/node.rb b/lib/arel/nodes/node.rb index a3eadf7170..36e7628612 100644 --- a/lib/arel/nodes/node.rb +++ b/lib/arel/nodes/node.rb @@ -51,8 +51,6 @@ module Arel ::Arel::Visitors::DepthFirst.new(block).accept self end - - def cast_reference?; false; end # :nodoc: end end end diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb index 74411a0522..2ef4837548 100644 --- a/lib/arel/predications.rb +++ b/lib/arel/predications.rb @@ -1,7 +1,7 @@ module Arel module Predications def not_eq other - Nodes::NotEqual.new self, other + Nodes::NotEqual.new self, Nodes.build_quoted(other, self) end def not_eq_any others @@ -44,8 +44,10 @@ module Arel else Nodes::Between.new(self, Nodes::And.new([Nodes.build_quoted(other.begin, self), Nodes.build_quoted(other.end, self)])) end - else + when Array Nodes::In.new self, other.map { |x| Nodes.build_quoted(x, self) } + else + Nodes::In.new self, Nodes.build_quoted(other, self) end end @@ -65,22 +67,24 @@ module Arel if other.begin == -Float::INFINITY && other.end == Float::INFINITY Nodes::In.new self, [] elsif other.end == Float::INFINITY - Nodes::LessThan.new(self, other.begin) + Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self)) elsif other.begin == -Float::INFINITY && other.exclude_end? - Nodes::GreaterThanOrEqual.new(self, other.end) + Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) elsif other.begin == -Float::INFINITY - Nodes::GreaterThan.new(self, other.end) + Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self)) elsif other.exclude_end? - left = Nodes::LessThan.new(self, other.begin) - right = Nodes::GreaterThanOrEqual.new(self, other.end) + left = Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self)) + right = Nodes::GreaterThanOrEqual.new(self, Nodes.build_quoted(other.end, self)) Nodes::Or.new left, right else - left = Nodes::LessThan.new(self, other.begin) - right = Nodes::GreaterThan.new(self, other.end) + left = Nodes::LessThan.new(self, Nodes.build_quoted(other.begin, self)) + right = Nodes::GreaterThan.new(self, Nodes.build_quoted(other.end, self)) Nodes::Or.new left, right end + when Array + Nodes::NotIn.new self, other.map { |x| Nodes.build_quoted(x, self) } else - Nodes::NotIn.new self, other + Nodes::NotIn.new self, Nodes.build_quoted(other, self) end end @@ -117,7 +121,7 @@ module Arel end def gteq right - Nodes::GreaterThanOrEqual.new self, right + Nodes::GreaterThanOrEqual.new self, Nodes.build_quoted(right, self) end def gteq_any others @@ -129,7 +133,7 @@ module Arel end def gt right - Nodes::GreaterThan.new self, right + Nodes::GreaterThan.new self, Nodes.build_quoted(right, self) end def gt_any others |