Class: Prequel::Relations::InnerJoin

Inherits:
Relation
  • Object
show all
Defined in:
lib/prequel/relations/inner_join.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Relation

#find, #get_column, #join, #project, #query, #singular_table_ref, #to_relation, #where

Constructor Details

#initialize(left_operand, right_operand, predicate) ⇒ InnerJoin

Returns a new instance of InnerJoin.



6
7
8
9
# File 'lib/prequel/relations/inner_join.rb', line 6

def initialize(left_operand, right_operand, predicate)
  @left, @right = left_operand.to_relation, right_operand.to_relation
  @predicate = resolve(predicate.to_predicate)
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



4
5
6
# File 'lib/prequel/relations/inner_join.rb', line 4

def left
  @left
end

#predicateObject (readonly)

Returns the value of attribute predicate.



4
5
6
# File 'lib/prequel/relations/inner_join.rb', line 4

def predicate
  @predicate
end

#rightObject (readonly)

Returns the value of attribute right.



4
5
6
# File 'lib/prequel/relations/inner_join.rb', line 4

def right
  @right
end

Instance Method Details

#columnsObject



15
16
17
18
19
# File 'lib/prequel/relations/inner_join.rb', line 15

def columns
  (left.columns + right.columns).map do |column|
    derive(column)
  end
end

#get_table(name) ⇒ Object



11
12
13
# File 'lib/prequel/relations/inner_join.rb', line 11

def get_table(name)
  left.get_table(name) || right.get_table(name)
end

#table_ref(query) ⇒ Object



28
29
30
# File 'lib/prequel/relations/inner_join.rb', line 28

def table_ref(query)
  Sql::InnerJoinedTableRef.new(left.table_ref(query), right.singular_table_ref(query), predicate.resolve_in_query(query))
end

#visit(query) ⇒ Object



21
22
23
24
25
26
# File 'lib/prequel/relations/inner_join.rb', line 21

def visit(query)
  query.table_ref = table_ref(query)
  query.select_list = columns.map do |derived_column|
    query.resolve_derived_column(derived_column, :qualified)
  end
end