method
through_record
v3.1.0 -
Show latest stable
- Class:
ActiveRecord::Associations::HasManyThroughAssociation
through_record(record)private
No documentation available.
# File activerecord/lib/active_record/associations/has_many_through_association.rb, line 52
def through_record(record)
through_association = owner.association(through_reflection.name)
attributes = construct_join_attributes(record)
through_record = Array.wrap(through_association.target).find { |candidate|
candidate.attributes.slice(*attributes.keys) == attributes
}
unless through_record
through_record = through_association.build(attributes)
through_record.send("#{source_reflection.name}=", record)
end
through_record
end