Class: ActiveRecord::Associations::HasManyThroughAssociation

Inherits:
HasManyAssociation show all
Includes:
ThroughAssociation
Defined in:
activerecord/lib/active_record/associations/has_many_through_association.rb

Overview

Active Record Has Many Through Association

Instance Attribute Summary

Attributes inherited from Association

#owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from HasManyAssociation

#handle_dependency

Methods included from ForeignAssociation

#foreign_key_present?, #nullified_owner_attributes

Methods inherited from CollectionAssociation

#add_to_target, #build, #delete, #delete_all, #destroy, #destroy_all, #empty?, #find, #find_from_target?, #ids_reader, #ids_writer, #include?, #load_target, #null_scope?, #reader, #replace, #reset, #scope, #size, #target=, #transaction, #writer

Methods inherited from Association

#create, #create!, #extensions, #initialize_attributes, #inversed_from, #klass, #load_target, #loaded!, #loaded?, #marshal_dump, #marshal_load, #reload, #remove_inverse_instance, #reset, #reset_negative_cache, #reset_scope, #scope, #set_inverse_instance, #set_inverse_instance_from_queries, #stale_target?

Constructor Details

#initialize(owner, reflection) ⇒ HasManyThroughAssociation

Returns a new instance of HasManyThroughAssociation.


9
10
11
12
# File 'activerecord/lib/active_record/associations/has_many_through_association.rb', line 9

def initialize(owner, reflection)
  super
  @through_records = {}
end

Instance Method Details

#concat(*records) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'activerecord/lib/active_record/associations/has_many_through_association.rb', line 14

def concat(*records)
  unless owner.new_record?
    records.flatten.each do |record|
      raise_on_type_mismatch!(record)
    end
  end

  super
end

#insert_record(record, validate = true, raise = false) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
# File 'activerecord/lib/active_record/associations/has_many_through_association.rb', line 24

def insert_record(record, validate = true, raise = false)
  ensure_not_nested

  if record.new_record? || record.has_changes_to_save?
    return unless super
  end

  save_through_record(record)

  record
end