Class: JoinClause

Inherits:
Object show all
Defined in:
lib/activeleopard/query_clauses/join_clause.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assoc_options, source_table) ⇒ JoinClause

Returns a new instance of JoinClause.



4
5
6
7
8
9
10
11
# File 'lib/activeleopard/query_clauses/join_clause.rb', line 4

def initialize(assoc_options, source_table)
  unless assoc_options
    raise InvalidInput, "Argument must be an association(type: symbol)"
  end

  @assoc_options = assoc_options
  @source_table = source_table
end

Instance Attribute Details

#assoc_optionsObject (readonly)

Returns the value of attribute assoc_options.



26
27
28
# File 'lib/activeleopard/query_clauses/join_clause.rb', line 26

def assoc_options
  @assoc_options
end

#source_tableObject (readonly)

Returns the value of attribute source_table.



26
27
28
# File 'lib/activeleopard/query_clauses/join_clause.rb', line 26

def source_table
  @source_table
end

Instance Method Details

#as_sqlObject



22
23
24
# File 'lib/activeleopard/query_clauses/join_clause.rb', line 22

def as_sql
  "JOIN #{other_table} ON #{on_clause} "
end

#on_clauseObject



17
18
19
20
# File 'lib/activeleopard/query_clauses/join_clause.rb', line 17

def on_clause
  "#{source_table}.#{assoc_options.own_join_column}" +
  " = " + "#{other_table}.#{assoc_options.other_join_column}"
end

#other_tableObject



13
14
15
# File 'lib/activeleopard/query_clauses/join_clause.rb', line 13

def other_table
  assoc_options.table_name
end