Class: ActiveRecord::Associations::HasManyThroughAssociation

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

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from HasManyAssociation

#construct_sql, #delete_records

Instance Method Details

#construct_conditionsObject



378
379
380
381
382
383
# File 'lib/composite_primary_keys/associations.rb', line 378

def construct_conditions
  raise 'polymorphic joins are not supported by composite_primary_keys' if @reflection.through_reflection.options[:as]
  conditions = full_columns_equals(@reflection.through_reflection.table_name, @reflection.through_reflection.primary_key_name, @owner.quoted_id)
  conditions << " AND (#{sql_conditions})" if sql_conditions
  conditions
end

#construct_joins(custom_joins = nil) ⇒ Object



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/composite_primary_keys/associations.rb', line 385

def construct_joins(custom_joins = nil)
  raise 'polymorphic joins are not supported by composite_primary_keys' if @reflection.through_reflection.options[:as] || @reflection.source_reflection.options[:as]
  
  if @reflection.source_reflection.macro == :belongs_to
    reflection_primary_key = @reflection.klass.primary_key
    source_primary_key     = @reflection.source_reflection.primary_key_name
  else
    reflection_primary_key = @reflection.source_reflection.primary_key_name
    source_primary_key     = @reflection.klass.primary_key
  end

  "INNER JOIN %s ON %s #{@reflection.options[:joins]} #{custom_joins}" % [
    @reflection.through_reflection.table_name,
    composite_join_clause(full_keys(@reflection.table_name, reflection_primary_key), full_keys(@reflection.through_reflection.table_name, source_primary_key))
  ]
end