diff --git a/lib/sequencer/unit/import/common/model/associations/extract.rb b/lib/sequencer/unit/import/common/model/associations/extract.rb index 40142b08e..07ce60302 100644 --- a/lib/sequencer/unit/import/common/model/associations/extract.rb +++ b/lib/sequencer/unit/import/common/model/associations/extract.rb @@ -12,14 +12,18 @@ class Sequencer def process state.provide(:associations) do associations.collect do |association| + + logger.debug("Checking association '#{association}'") next if !mapped.key?(association) # remove from the mapped values if it's an association value = mapped.delete(association) + logger.debug("Extracted association '#{association}' value '#{value.inspect}'") # skip if we don't track them next if tracked_associations.exclude?(association) + logger.debug("Using value of association '#{association}'") [association, value] end.compact.to_h end @@ -29,9 +33,8 @@ class Sequencer def associations @associations ||= begin - associations = [] # loop over all reflections - model_class.reflect_on_all_associations.each do |reflection| + model_class.reflect_on_all_associations.each_with_object([]) do |reflection, associations| # refection name is something like groups or organization (singular/plural) associations.push(reflection.name) @@ -41,14 +44,13 @@ class Sequencer # add trailing 's' to get pluralized key reflection_name = reflection.name.to_s - if reflection_name.singularize == reflection_name + if reflection_name.singularize != reflection_name key = "#{key}s" end # store _id/_ids name associations.push(key.to_sym) end - associations end end