Module: ActiveRecord::Associations::ForeignAssociation
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | activerecord/lib/active_record/associations/foreign_association.rb |
Instance Attribute Summary
- #foreign_key_present? ⇒ Boolean readonly
Instance Method Summary
- #nullified_owner_attributes
-
#set_owner_attributes(record)
private
Sets the owner attributes on the given record.
Instance Attribute Details
#foreign_key_present? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'activerecord/lib/active_record/associations/foreign_association.rb', line 5
def foreign_key_present? if reflection.klass.primary_key owner.attribute_present?(reflection.active_record_primary_key) else false end end
Instance Method Details
#nullified_owner_attributes
[ GitHub ]#set_owner_attributes(record) (private)
Sets the owner attributes on the given record
# File 'activerecord/lib/active_record/associations/foreign_association.rb', line 22
def set_owner_attributes(record) return if [:through] primary_key_attribute_names = Array(reflection.join_primary_key) foreign_key_attribute_names = Array(reflection.join_foreign_key) primary_key_foreign_key_pairs = primary_key_attribute_names.zip(foreign_key_attribute_names) primary_key_foreign_key_pairs.each do |primary_key, foreign_key| value = owner._read_attribute(foreign_key) record._write_attribute(primary_key, value) end if reflection.type record._write_attribute(reflection.type, owner.class.polymorphic_name) end end