Fixes customizable journal comparison

pull/582/head
Hagen Schink 11 years ago
parent 40d3ee37cf
commit f4a5fc88ea
  1. 8
      app/models/journal_manager.rb

@ -63,6 +63,8 @@ class JournalManager
current = journable.send(association).map {|a| { key.to_s => a.send(id), value.to_s => a.send(value)} }
predecessor = journable.journals.last.send(journal_assoc_name).map(&:attributes)
current = remove_empty_associations(current, value.to_s)
merged_journals = JournalManager.merge_reference_journals_by_id current, predecessor, key.to_s
changes.merge! JournalManager.added_references(merged_journals, association.to_s, value.to_s)
@ -75,6 +77,10 @@ class JournalManager
end
end
def self.remove_empty_associations(associations, value)
associations.reject { |h| h.has_key?(value) && h[value].blank? }
end
def self.merge_reference_journals_by_id(current, predecessor, key)
all_attachable_journal_ids = current.map { |j| j[key] } | predecessor.map { |j| j[key] }
@ -225,7 +231,7 @@ class JournalManager
end
def self.create_custom_field_data(journable, journal)
journable.custom_values.each do |cv|
journable.custom_values.select { |c| !c.value.blank? }.each do |cv|
journal.customizable_journals.build custom_field_id: cv.custom_field_id, value: cv.value
end
end

Loading…
Cancel
Save