One more Version scope for PaperTrail::Model.

This commit is contained in:
Emmanuel Gomez 2011-02-05 23:44:56 -08:00
parent 9fc312c129
commit a23144fc04
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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",