From 6812c581c6744b5c129415eb223cd03af459616c Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 30 Aug 2017 17:12:28 +0200 Subject: [PATCH] - Fixed bug: Pluralization of association name is inverted. - Refactoring: Usage of each_with_object to cleanup code. - Refactoring: Improved logging for association extraction. --- .../unit/import/common/model/associations/extract.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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