lib/copyable/declarations/associations.rb in copyable-0.1.2 vs lib/copyable/declarations/associations.rb in copyable-0.2.0
- old
+ new
@@ -4,13 +4,14 @@
class << self
# this is the algorithm for copying associated records according to the
# instructions given in the copyable declaration
- def execute(association_list, original_model, new_model, skip_validations, skip_associations)
+ def execute(association_list, original_model, new_model, global_override = {}, skip_validations, skip_associations)
@skip_validations = skip_validations
@skip_associations = skip_associations
+ @global_override = global_override
association_list.each do |assoc_name, advice|
association = original_model.class.reflections[assoc_name.to_sym]
check_advice(association, advice, original_model)
unless advice == :do_not_copy || skip_associations.include?(assoc_name.to_sym)
copy_association(association, original_model, new_model)
@@ -77,9 +78,10 @@
if SingleCopyEnforcer.can_copy?(original_record)
if original_record.respond_to? :create_copy!
copied_record = original_record.create_copy!(
override: { association.foreign_key => parent_model.id },
__called_recursively: true,
+ global_override: @global_override,
skip_validations: @skip_validations,
skip_associations: @skip_associations)
else
message = "Could not copy #{parent_model.class.name}#id:#{parent_model.id} "
message << "because #{original_record.class.name} does not have a copyable declaration."