Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merged pull request #51 from thinkcast/master.

Removed hardcoded primary key from versions
  • Loading branch information...
commit b71fb81f2d244211f0e1318cfd6011522d8e0b03 2 parents 20e049a + 91eab1a
@airblade authored
View
2  lib/paper_trail/has_paper_trail.rb
@@ -41,7 +41,7 @@ def has_paper_trail(options = {})
cattr_accessor :paper_trail_enabled_for_model
self.paper_trail_enabled_for_model = true
- has_many :versions, :class_name => version_class_name, :as => :item, :order => 'created_at ASC, id ASC'
+ has_many :versions, :class_name => version_class_name, :as => :item, :order => "created_at ASC, #{self.primary_key} ASC"
after_create :record_create
before_update :record_update
View
6 lib/paper_trail/version.rb
@@ -7,16 +7,16 @@ def self.with_item_keys(item_type, item_id)
end
scope :subsequent, lambda { |version|
- where(["id > ?", version.is_a?(self) ? version.id : version]).order("id ASC")
+ where(["#{self.primary_key} > ?", version.is_a?(self) ? version.id : version]).order("#{self.primary_key} ASC")
}
scope :preceding, lambda { |version|
- where(["id < ?", version.is_a?(self) ? version.id : version]).order("id DESC")
+ where(["#{self.primary_key} < ?", version.is_a?(self) ? version.id : version]).order("#{self.primary_key} DESC")
}
scope :after, lambda { |timestamp|
# TODO: is this :order necessary, considering its presence on the has_many :versions association?
- where(['created_at > ?', timestamp]).order('created_at ASC, id ASC')
+ where(['created_at > ?', timestamp]).order("created_at ASC, #{self.primary_key} ASC")
}
# Restore the item from this version.
Please sign in to comment.
Something went wrong with that request. Please try again.