Module: ActiveRecord::Associations::ForeignAssociation

Included in:
HasManyAssociation, HasOneAssociation
Defined in:
lib/active_record/associations/foreign_association.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#foreign_key_present?Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
# File '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

#nullified_owner_attributesObject



13
14
15
16
17
18
# File 'lib/active_record/associations/foreign_association.rb', line 13

def nullified_owner_attributes
  Hash.new.tap do |attrs|
    attrs[reflection.foreign_key] = nil
    attrs[reflection.type] = nil if reflection.type.present?
  end
end