1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

Simplifying the nil attribute assignment fix, and making it so that it only happens when the item to be reified is the current version of the model

This commit is contained in:
Ben Atkins 2013-05-13 10:17:07 -04:00
parent 05468001af
commit e6ae05ea99

View file

@ -72,6 +72,8 @@ class Version < ActiveRecord::Base
if item
model = item
# Look for attributes that exist in the model and not in this version. These attributes should be set to nil.
(model.attribute_names - attrs.keys).each { |k| attrs[k] = nil }
else
inheritance_column_name = item_type.constantize.inheritance_column
class_name = attrs[inheritance_column_name].blank? ? item_type : attrs[inheritance_column_name]
@ -81,12 +83,6 @@ class Version < ActiveRecord::Base
model.class.unserialize_attributes_for_paper_trail attrs
# Look for attributes that exist in the model and not in this version.
# These attributes should be set to nil.
(model.attribute_names - attrs.keys).each do |k|
attrs[k] = nil
end
# Set all the attributes in this version on the model
attrs.each do |k, v|
if model.respond_to?("#{k}=")