diff --git a/activerecord/lib/arel.rb b/activerecord/lib/arel.rb index 6263ef42ad..b7a53fd8ea 100644 --- a/activerecord/lib/arel.rb +++ b/activerecord/lib/arel.rb @@ -51,11 +51,8 @@ module Arel when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual, Arel::Nodes::LessThan, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThan, Arel::Nodes::GreaterThanOrEqual - if value.left.is_a?(Arel::Attributes::Attribute) - yield value.left - elsif value.right.is_a?(Arel::Attributes::Attribute) - yield value.right - end + attribute_value = value.detect_attribute + yield attribute_value if attribute_value when Arel::Nodes::Or fetch_attribute(value.left, &block) && fetch_attribute(value.right, &block) when Arel::Nodes::Grouping diff --git a/activerecord/lib/arel/nodes/binary.rb b/activerecord/lib/arel/nodes/binary.rb index e184e99c73..258000025f 100644 --- a/activerecord/lib/arel/nodes/binary.rb +++ b/activerecord/lib/arel/nodes/binary.rb @@ -11,6 +11,14 @@ module Arel # :nodoc: all @right = right end + def detect_attribute + if self.left.is_a?(Arel::Attributes::Attribute) + self.left + elsif self.right.is_a?(Arel::Attributes::Attribute) + self.right + end + end + def initialize_copy(other) super @left = @left.clone if @left