Class: Copyable::Declarations::Associations

Inherits:
Declaration
  • Object
show all
Defined in:
lib/copyable/declarations/associations.rb

Class Method Summary collapse

Methods inherited from Declaration

method_name, required?

Class Method Details

.execute(association_list, original_model, new_model, global_override = {}, skip_validations, skip_associations) ⇒ Object

this is the algorithm for copying associated records according to the instructions given in the copyable declaration



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/copyable/declarations/associations.rb', line 9

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_s]
    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)
    end
  end
end