Skip to content

Commit 607aea8

Browse files
committed
Add reify_original method.
Returning the original version is a common use-case and is not as easy as it should be, particularly because calling `reify` on the first version returns `nil`, which is the `object` *before* it was created. This method simply tries to `reify` from the *second* version, if it exists. If it doesn’t exist (i.e. there has not been any changes to the object), it falls back to `self`, which is the original and *only* version of the object. Fixes #1204.
1 parent 94e9c0d commit 607aea8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Diff for: lib/paper_trail/record_trail.rb

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def record_create
6969
end
7070
end
7171

72+
# Returns the original version of this object or just this object if there has been no changes.
73+
#
74+
# @api public
75+
def reify_original
76+
versions.second&.reify || @record
77+
end
78+
7279
# `recording_order` is "after" or "before". See ModelConfig#on_destroy.
7380
#
7481
# @api private

0 commit comments

Comments
 (0)