Class: CommaHeaven::Sqler::Column
- Inherits:
-
Struct
- Object
- Struct
- CommaHeaven::Sqler::Column
- Defined in:
- lib/comma-heaven/sqler/column.rb
Instance Attribute Summary collapse
-
#as ⇒ Object
Returns the value of attribute as.
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
Instance Attribute Details
#as ⇒ Object
Returns the value of attribute as
5 6 7 |
# File 'lib/comma-heaven/sqler/column.rb', line 5 def as @as end |
#attribute ⇒ Object
Returns the value of attribute attribute
5 6 7 |
# File 'lib/comma-heaven/sqler/column.rb', line 5 def attribute @attribute end |
#parent ⇒ Object
Returns the value of attribute parent
5 6 7 |
# File 'lib/comma-heaven/sqler/column.rb', line 5 def parent @parent end |
#position ⇒ Object
Returns the value of attribute position
5 6 7 |
# File 'lib/comma-heaven/sqler/column.rb', line 5 def position @position end |
Instance Method Details
#joins ⇒ Object
12 13 14 15 16 |
# File 'lib/comma-heaven/sqler/column.rb', line 12 def joins sql = join_clause sql << " AND #{table_alias}.#{association.klass.primary_key} IN (SELECT #{association.klass.primary_key} FROM #{association.quoted_table_name} WHERE #{model.send(:sanitize_sql, association.[:conditions])})" if parent.respond_to?(:association) && association.[:conditions] sql.gsub(/\n/, '').squeeze(' ').strip end |
#select ⇒ Object
8 9 10 |
# File 'lib/comma-heaven/sqler/column.rb', line 8 def select "#{table_alias}.#{attribute} AS #{quote(sql_as)}" end |
#sql_as ⇒ Object
18 19 20 21 |
# File 'lib/comma-heaven/sqler/column.rb', line 18 def sql_as return as % index if as return [table_alias(:singularize).gsub(/^_+/, ''), attribute].compact.join('_') end |