Sha256: c7da261fb6344e8d346efca59bd2c35313929a841f64f3a1aaafc75cf048ed04

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module Arel
  class Join < Relation
    attributes :relation1, :relation2, :predicates
    deriving :==
    delegate :name, :to => :relation1

    def initialize(relation1, relation2 = Nil.instance, *predicates)
      @relation1, @relation2, @predicates = relation1, relation2, predicates
    end

    def hash
      @hash ||= :relation1.hash
    end

    def eql?(other)
      self == other
    end

    def attributes
      @attributes ||= (relation1.externalize.attributes +
        relation2.externalize.attributes).collect { |a| a.bind(self) }
    end

    def wheres
      # TESTME bind to self?
      relation1.externalize.wheres
    end

    def ons
      @ons ||= @predicates.collect { |p| p.bind(self) }
    end

    # TESTME
    def externalizable?
      relation1.externalizable? or relation2.externalizable?
    end

    def join?
      true
    end

    def engine
      relation1.engine != relation2.engine ? Memory::Engine.new : relation1.engine
    end
  end

  class InnerJoin  < Join; end
  class OuterJoin  < Join; end
  class StringJoin < Join
    def attributes
      relation1.externalize.attributes
    end

    def engine
      relation1.engine
    end
  end

  class Relation
    def join?
      false
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arel-0.2.pre lib/arel/algebra/relations/operations/join.rb
arel-0.1.2 lib/arel/algebra/relations/operations/join.rb
arel-0.1.0 lib/arel/algebra/relations/operations/join.rb