Class: CommaHeaven::Sqler::AssociationColumns
- Defined in:
- lib/comma-heaven/sqler/association_columns.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#association ⇒ Object
Returns the value of attribute association.
-
#position ⇒ Object
Returns the value of attribute position.
Attributes inherited from Columns
#index, #model, #options, #parent
Instance Method Summary collapse
- #foreign_key_for(an_association) ⇒ Object
-
#initialize(association, export, position, parent, index = nil, options = {}) ⇒ AssociationColumns
constructor
@parent@ is the parameter for passing a reference to the containing columns array.
- #prefix ⇒ Object
- #table_alias(method = :pluralize) ⇒ Object
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, = {}) self.parent = parent self.position = position self.association = association self.index = index super(association.klass, export, ) end |
Instance Attribute Details
#association ⇒ Object
Returns the value of attribute association.
4 5 6 |
# File 'lib/comma-heaven/sqler/association_columns.rb', line 4 def association @association end |
#position ⇒ Object
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 |
#prefix ⇒ Object
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 |