Class: DuckRecord::Associations::HasOneAssociation

Inherits:
SingularAssociation show all
Includes:
ForeignAssociation
Defined in:
lib/duck_record/associations/has_one_association.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Association

#owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from SingularAssociation

#build, #force_reload_reader, #reader, #writer

Methods inherited from Association

#aliased_table_name, #association_scope, #create, #create!, #extensions, #initialize, #initialize_attributes, #interpolate, #klass, #load_target, #loaded!, #loaded?, #marshal_dump, #marshal_load, #reload, #remove_inverse_instance, #reset, #reset_scope, #scope, #set_inverse_instance, #stale_target?, #target_scope

Constructor Details

This class inherits a constructor from DuckRecord::Associations::Association

Instance Method Details

#replace(record) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/duck_record/associations/has_one_association.rb', line 7

def replace(record)
  if owner.class.readonly_attributes.include?(reflection.foreign_key.to_s)
    return
  end

  raise_on_type_mismatch!(record) if record
  load_target

  return target unless target || record

  self.target = record
end