Module: ActiveRecord::Bitemporal::Patches::Persistence

Defined in:
lib/activerecord-bitemporal/patches.rb

Overview

nested_attributes 用の拡張

Instance Method Summary collapse

Instance Method Details

#assign_nested_attributes_for_collection_association(association_name, _attributes_collection) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/activerecord-bitemporal/patches.rb', line 40

def assign_nested_attributes_for_collection_association(association_name, _attributes_collection)
  # Preloading records
  send(association_name).load if association(association_name).klass&.bi_temporal_model?
  super
  send(association_name)&.each do |target|
    next unless target.changed?
    copy_bitemporal_option(self, target)
  end
end

#assign_nested_attributes_for_one_to_one_association(association_name, _attributes) ⇒ Object

MEMO: このメソッドは BTDM 以外にもフックする必要がある



33
34
35
36
37
38
# File 'lib/activerecord-bitemporal/patches.rb', line 33

def assign_nested_attributes_for_one_to_one_association(association_name, _attributes)
  super
  target = send(association_name)
  return if target.nil? || !target.changed?
  copy_bitemporal_option(self, target)
end