Class: ActiveRecord::Associations::HasOneAssociation

Inherits:
BelongsToAssociation
  • Object
show all
Defined in:
lib/composite_primary_keys/associations.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#construct_sqlObject



298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/composite_primary_keys/associations.rb', line 298

def construct_sql
  case
    when @reflection.options[:as]
      @finder_sql = 
        "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_id = #{@owner.quoted_id} AND " + 
        "#{@reflection.klass.table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}"          
    else
      @finder_sql = full_columns_equals(@reflection.klass.table_name, 
                              @reflection.primary_key_name, @owner.quoted_id)
  end
  @finder_sql << " AND (#{conditions})" if conditions
end