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_conditions_with_composite_keysObject



398
399
400
401
402
403
404
405
406
# File 'lib/composite_primary_keys/associations.rb', line 398

def construct_conditions_with_composite_keys
  if @reflection.through_reflection.options[:as]
    construct_conditions_without_composite_keys
  else
    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
end

#construct_joins_with_composite_keys(custom_joins = nil) ⇒ Object



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/composite_primary_keys/associations.rb', line 409

def construct_joins_with_composite_keys(custom_joins = nil)
  if @reflection.through_reflection.options[:as] || @reflection.source_reflection.options[:as]
    construct_joins_without_composite_keys(custom_joins)
  else
    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.quoted_table_name,
      composite_join_clause(full_keys(@reflection.table_name, reflection_primary_key), full_keys(@reflection.through_reflection.table_name, source_primary_key))
    ]
  end
end