Class: Amoeba::Macros::HasOne

Inherits:
Base
  • Object
show all
Defined in:
lib/amoeba/macros/has_one.rb

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize, #remapped_relation_name

Constructor Details

This class inherits a constructor from Amoeba::Macros::Base

Instance Method Details

#follow(relation_name, association) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/amoeba/macros/has_one.rb', line 6

def follow(relation_name, association)
  return if association.is_a?(::ActiveRecord::Reflection::ThroughReflection)

  old_obj = @old_object.__send__(relation_name)
  return unless old_obj

  copy_of_obj = old_obj.amoeba_dup(@options)
  copy_of_obj[:"#{association.foreign_key}"] = nil
  relation_name = remapped_relation_name(relation_name)
  @new_object.__send__(:"#{relation_name}=", copy_of_obj)
end