Class: CommaHeaven::Sqler::AssociationColumns

Inherits:
Columns
  • Object
show all
Defined in:
lib/comma-heaven/sqler/association_columns.rb

Direct Known Subclasses

BelongsToColumns, HasManyColumns, HasOneColumns

Instance Attribute Summary collapse

Attributes inherited from Columns

#index, #model, #options, #parent

Instance Method Summary collapse

Methods inherited from Columns

#join_clause, #joins, #select, #sql_as, #table

Constructor Details

#initialize(association, export, position, parent, index = nil, options = {}) ⇒ AssociationColumns

@parent@ is the parameter for passing a reference to the containing columns array



8
9
10
11
12
13
14
# File 'lib/comma-heaven/sqler/association_columns.rb', line 8

def initialize(association, export, position, parent, index = nil, options = {})
  self.parent = parent
  self.position = position
  self.association = association
  self.index = index
  super(association.klass, export, options)
end

Instance Attribute Details

#associationObject

Returns the value of attribute association.



4
5
6
# File 'lib/comma-heaven/sqler/association_columns.rb', line 4

def association
  @association
end

#positionObject

Returns the value of attribute position.



4
5
6
# File 'lib/comma-heaven/sqler/association_columns.rb', line 4

def position
  @position
end

Instance Method Details

#foreign_key_for(an_association) ⇒ Object



16
17
18
# File 'lib/comma-heaven/sqler/association_columns.rb', line 16

def foreign_key_for(an_association)
  an_association.respond_to?(:foreign_key) ? an_association.foreign_key : an_association.primary_key_name
end

#prefixObject



26
27
28
# File 'lib/comma-heaven/sqler/association_columns.rb', line 26

def prefix
  return "_"
end

#table_alias(method = :pluralize) ⇒ Object



20
21
22
23
24
# File 'lib/comma-heaven/sqler/association_columns.rb', line 20

def table_alias(method = :pluralize)
  t = association.name.to_s.send(method)
  
  return prefix + [((parent && parent.parent) ? parent.table_alias(method) : nil), t, index].compact.join('_')
end