- Fixed bug: Pluralization of association name is inverted.
- Refactoring: Usage of each_with_object to cleanup code. - Refactoring: Improved logging for association extraction.
This commit is contained in:
parent
4aae89b2b0
commit
6812c581c6
1 changed files with 6 additions and 4 deletions
|
@ -12,14 +12,18 @@ class Sequencer
|
||||||
def process
|
def process
|
||||||
state.provide(:associations) do
|
state.provide(:associations) do
|
||||||
associations.collect do |association|
|
associations.collect do |association|
|
||||||
|
|
||||||
|
logger.debug("Checking association '#{association}'")
|
||||||
next if !mapped.key?(association)
|
next if !mapped.key?(association)
|
||||||
|
|
||||||
# remove from the mapped values if it's an association
|
# remove from the mapped values if it's an association
|
||||||
value = mapped.delete(association)
|
value = mapped.delete(association)
|
||||||
|
logger.debug("Extracted association '#{association}' value '#{value.inspect}'")
|
||||||
|
|
||||||
# skip if we don't track them
|
# skip if we don't track them
|
||||||
next if tracked_associations.exclude?(association)
|
next if tracked_associations.exclude?(association)
|
||||||
|
|
||||||
|
logger.debug("Using value of association '#{association}'")
|
||||||
[association, value]
|
[association, value]
|
||||||
end.compact.to_h
|
end.compact.to_h
|
||||||
end
|
end
|
||||||
|
@ -29,9 +33,8 @@ class Sequencer
|
||||||
|
|
||||||
def associations
|
def associations
|
||||||
@associations ||= begin
|
@associations ||= begin
|
||||||
associations = []
|
|
||||||
# loop over all reflections
|
# 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)
|
# refection name is something like groups or organization (singular/plural)
|
||||||
associations.push(reflection.name)
|
associations.push(reflection.name)
|
||||||
|
@ -41,14 +44,13 @@ class Sequencer
|
||||||
|
|
||||||
# add trailing 's' to get pluralized key
|
# add trailing 's' to get pluralized key
|
||||||
reflection_name = reflection.name.to_s
|
reflection_name = reflection.name.to_s
|
||||||
if reflection_name.singularize == reflection_name
|
if reflection_name.singularize != reflection_name
|
||||||
key = "#{key}s"
|
key = "#{key}s"
|
||||||
end
|
end
|
||||||
|
|
||||||
# store _id/_ids name
|
# store _id/_ids name
|
||||||
associations.push(key.to_sym)
|
associations.push(key.to_sym)
|
||||||
end
|
end
|
||||||
associations
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue