Class: Babik::QuerySet::Join::AbstractJoin
- Inherits:
-
Object
- Object
- Babik::QuerySet::Join::AbstractJoin
- Defined in:
- lib/babik/queryset/lib/join/join.rb
Overview
A table join
Direct Known Subclasses
Instance Attribute Summary collapse
-
#origin_table ⇒ Object
readonly
Returns the value of attribute origin_table.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
-
#target_table ⇒ Object
readonly
Returns the value of attribute target_table.
Instance Method Summary collapse
-
#_init_sql ⇒ Object
Initialize SQL of the JOIN.
-
#initialize(target_table, origin_table) ⇒ AbstractJoin
constructor
Construct a Join.
-
#target_alias ⇒ String
Return the target table alias.
Constructor Details
#initialize(target_table, origin_table) ⇒ AbstractJoin
Construct a Join
32 33 34 35 36 |
# File 'lib/babik/queryset/lib/join/join.rb', line 32 def initialize(target_table, origin_table) @target_table = target_table @origin_table = origin_table _init_sql end |
Instance Attribute Details
#origin_table ⇒ Object (readonly)
Returns the value of attribute origin_table.
27 28 29 |
# File 'lib/babik/queryset/lib/join/join.rb', line 27 def origin_table @origin_table end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
27 28 29 |
# File 'lib/babik/queryset/lib/join/join.rb', line 27 def sql @sql end |
#target_table ⇒ Object (readonly)
Returns the value of attribute target_table.
27 28 29 |
# File 'lib/babik/queryset/lib/join/join.rb', line 27 def target_table @target_table end |
Instance Method Details
#_init_sql ⇒ Object
Initialize SQL of the JOIN
39 40 41 42 43 44 45 |
# File 'lib/babik/queryset/lib/join/join.rb', line 39 def _init_sql # Create the SQL code of the join @sql = %( #{self.class::JOIN_TYPE} JOIN #{@target_table.name} #{@target_table.table_alias} ON #{@target_table.table_alias}.#{@target_table.key} = #{@origin_table.table_alias}.#{@origin_table.key} ).delete("\n").gsub(/\s{2,}/, ' ').strip end |
#target_alias ⇒ String
Return the target table alias.
49 50 51 |
# File 'lib/babik/queryset/lib/join/join.rb', line 49 def target_alias @target_table.table_alias end |