Class: ActiveRecord::Associations::HasOneThroughAssociation

Inherits:
HasManyThroughAssociation show all
Defined in:
lib/active_record/associations/has_one_through_association.rb

Instance Method Summary collapse

Methods inherited from HasManyThroughAssociation

#create, #create!, #initialize, #size

Methods inherited from AssociationCollection

#<<, #any?, #build, #clear, #count, #create, #create!, #delete, #delete_all, #destroy_all, #empty?, #first, #include?, #initialize, #last, #length, #proxy_respond_to?, #replace, #reset, #size, #sum, #to_ary, #transaction, #uniq

Methods inherited from AssociationProxy

#===, #aliased_table_name, #conditions, #initialize, #inspect, #loaded, #loaded?, #proxy_owner, #proxy_reflection, #proxy_respond_to?, #proxy_target, #reload, #reset, #respond_to?, #send, #target, #target=

Constructor Details

This class inherits a constructor from ActiveRecord::Associations::HasManyThroughAssociation

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveRecord::Associations::AssociationCollection

Instance Method Details

#create_through_record(new_value) ⇒ Object

nodoc:



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/active_record/associations/has_one_through_association.rb', line 5

def create_through_record(new_value) #nodoc:
  klass = @reflection.through_reflection.klass

  current_object = @owner.send(@reflection.through_reflection.name)
  
  if current_object
    current_object.update_attributes(construct_join_attributes(new_value))
  else
    @owner.send(@reflection.through_reflection.name,  klass.send(:create, construct_join_attributes(new_value)))
  end
end