Skip to content

Commit

Permalink
issue mongoid#34, handle nil value of original value of embedded rela…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
vanboom committed Jul 22, 2020
1 parent 46c1804 commit d56491a
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions lib/mongoid/history/attributes/update.rb
Expand Up @@ -90,14 +90,8 @@ def embeds_many_changes_from_parent(relation, value)
relation = trackable_class.database_field_name(relation)
relation_class = trackable_class.relation_class_of(relation)
paranoia_field = Mongoid::History.trackable_class_settings(relation_class)[:paranoia_field]

# DVB only process if the original value of the embedded relation is not nil
original_value = if value[0].present?
value[0].reject { |rel| rel[paranoia_field].present? }
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
else
nil
end
original_value = (value[0] || []).reject { |rel| rel[paranoia_field].present? }
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
modified_value = value[1].reject { |rel| rel[paranoia_field].present? }
.map { |v_attrs| format_embeds_many_relation(relation, v_attrs) }
return if original_value == modified_value
Expand Down

0 comments on commit d56491a

Please sign in to comment.