From f4a5fc88ea77e88d41a9a7071c7438a8a72a1b97 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Fri, 1 Nov 2013 09:27:18 +0100 Subject: [PATCH] Fixes customizable journal comparison --- app/models/journal_manager.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/journal_manager.rb b/app/models/journal_manager.rb index 8fa5768b60..282a132348 100644 --- a/app/models/journal_manager.rb +++ b/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