Skip to content

Commit

Permalink
Use updated_at timestamp for "create" versions
Browse files Browse the repository at this point in the history
"Create" versions currently use the item's created_at field to set the version's timestamp. 

This is wrong in the case where the item was created at some point in the past, then deleted, then is now being created again (e.g., through reification). The version gets the timestamp from the original creation.

Instead, this change uses the item's updated_at field which is the time of the re-creation. This is also consistent with what happens in "update" versions
  • Loading branch information
ItaiLeibowitz committed Aug 11, 2015
1 parent 87917e0 commit 245e835
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ def record_create
:event => paper_trail_event || 'create',
:whodunnit => PaperTrail.whodunnit
}
if respond_to?(:created_at)
data[PaperTrail.timestamp_field] = created_at
if respond_to?(:updated_at)
data[PaperTrail.timestamp_field] = updated_at
end
if paper_trail_options[:save_changes] && changed_notably? && self.class.paper_trail_version_class.column_names.include?('object_changes')
data[:object_changes] = self.class.paper_trail_version_class.object_changes_col_is_json? ? changes_for_paper_trail :
Expand Down

0 comments on commit 245e835

Please sign in to comment.