One more Version scope for PaperTrail::Model.
This commit is contained in:
parent
9fc312c129
commit
a23144fc04
|
@ -71,7 +71,7 @@ module PaperTrail
|
|||
def version_at(timestamp)
|
||||
# Because a version stores how its object looked *before* the change,
|
||||
# we need to look for the first version created *after* the timestamp.
|
||||
version = versions.first :conditions => ['created_at > ?', timestamp], :order => 'created_at ASC, id ASC'
|
||||
version = versions.after(timestamp).first
|
||||
version ? version.reify : self
|
||||
end
|
||||
|
||||
|
|
|
@ -16,6 +16,12 @@ class Version < ActiveRecord::Base
|
|||
:order => "id DESC",
|
||||
} }
|
||||
|
||||
named_scope :after, lambda { |timestamp| {
|
||||
:conditions => ['created_at > ?', timestamp],
|
||||
# TODO: is this :order necessary, considering its presence on the has_many :versions association?
|
||||
:order => 'created_at ASC, id ASC'
|
||||
} }
|
||||
|
||||
# Restore the item from this version.
|
||||
#
|
||||
# This will automatically restore all :has_one associations as they were "at the time",
|
||||
|
|
Loading…
Reference in New Issue