class NinjaModel::Associations::BelongsToAssociation
Public Instance Methods
replace(record)
click to toggle source
# File lib/ninja_model/associations/belongs_to_association.rb, line 5 def replace(record) raise_on_type_mismatch(record) if record replace_keys(record) @updated = true if record self.target = record end
updated?()
click to toggle source
# File lib/ninja_model/associations/belongs_to_association.rb, line 15 def updated? @updated end
Private Instance Methods
different_target?(record)
click to toggle source
# File lib/ninja_model/associations/belongs_to_association.rb, line 25 def different_target?(record) record.nil? && owner[reflection.foreign_key] || record && record.id != owner[reflection.foreign_key] end
find_target?()
click to toggle source
# File lib/ninja_model/associations/belongs_to_association.rb, line 21 def find_target? !loaded? && foreign_key_present? && klass end
foreign_key_present?()
click to toggle source
# File lib/ninja_model/associations/belongs_to_association.rb, line 38 def foreign_key_present? owner[reflection.foreign_key] end
replace_keys(record)
click to toggle source
# File lib/ninja_model/associations/belongs_to_association.rb, line 30 def replace_keys(record) if record owner[reflection.foreign_key] = record[reflection.association_primary_key(record.class)] else owner[reflection.foreign_key] = nil end end
target_id()
click to toggle source
# File lib/ninja_model/associations/belongs_to_association.rb, line 42 def target_id if options[:primary_key] owner.send(reflection.name).try(:id) else owner[reflection.foreign_key] end end