diff options
-rw-r--r-- | lib/arel/algebra/relations/operations/having.rb | 11 | ||||
-rw-r--r-- | lib/arel/algebra/relations/operations/join.rb | 26 |
2 files changed, 26 insertions, 11 deletions
diff --git a/lib/arel/algebra/relations/operations/having.rb b/lib/arel/algebra/relations/operations/having.rb index daca1f7bce..fdd35626af 100644 --- a/lib/arel/algebra/relations/operations/having.rb +++ b/lib/arel/algebra/relations/operations/having.rb @@ -1,16 +1,21 @@ module Arel class Having < Compound - attributes :relation, :predicates - deriving :== + attr_reader :predicates def initialize(relation, *predicates) + super(relation) predicates = [yield(relation)] + predicates if block_given? @predicates = predicates.map { |p| p.bind(relation) } - @relation = relation end def havings @havings ||= relation.havings + predicates end + + def == other + super || Having === other && + relation == other.relation && + predicates == other.predicates + end end end diff --git a/lib/arel/algebra/relations/operations/join.rb b/lib/arel/algebra/relations/operations/join.rb index 21bcfaa62d..dd67e8a9bf 100644 --- a/lib/arel/algebra/relations/operations/join.rb +++ b/lib/arel/algebra/relations/operations/join.rb @@ -2,20 +2,20 @@ module Arel class Join include Relation - attributes :relation1, :relation2, :predicates - deriving :== - delegate :name, :to => :relation1 + attr_reader :relation1, :relation2, :predicates def initialize(relation1, relation2 = Nil.instance, *predicates) - @relation1, @relation2, @predicates = relation1, relation2, predicates + @relation1 = relation1 + @relation2 = relation2 + @predicates = predicates end - def hash - @hash ||= :relation1.hash + def name + relation1.name end - def eql?(other) - self == other + def hash + @hash ||= :relation1.hash end def attributes @@ -43,6 +43,16 @@ module Arel def engine relation1.engine != relation2.engine ? Memory::Engine.new : relation1.engine end + + def == other + super || Join === other && + relation1 == other.relation1 && + relation2 == other.relation2 && + predicates == other.predicates + end + + # FIXME remove this. :'( + alias :eql? :== end class InnerJoin < Join; end |