Skip to content

Commit

Permalink
Merged pull request #51 from thinkcast/master.
Browse files Browse the repository at this point in the history
Removed hardcoded primary key from versions
  • Loading branch information
airblade committed Apr 28, 2011
2 parents 20e049a + 91eab1a commit b71fb81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/paper_trail/has_paper_trail.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/paper_trail/version.rb
Expand Up @@ -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.
Expand Down

0 comments on commit b71fb81

Please sign in to comment.