mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Further changes to use user-defined primary key as opposed to id
This commit is contained in:
parent
4adaa875b7
commit
aba0fc30d4
1 changed files with 4 additions and 4 deletions
|
@ -8,11 +8,11 @@ class Version < ActiveRecord::Base
|
|||
end
|
||||
|
||||
scope :subsequent, lambda { |version|
|
||||
where(["#{self.primary_key} > ?", version.is_a?(self) ? version.id : version]).order("#{self.primary_key} ASC")
|
||||
where(["#{self.primary_key} > ?", version.is_a?(self) ? version.send(self.primary_key) : version]).order("#{self.primary_key} ASC")
|
||||
}
|
||||
|
||||
scope :preceding, lambda { |version|
|
||||
where(["#{self.primary_key} < ?", version.is_a?(self) ? version.id : version]).order("#{self.primary_key} DESC")
|
||||
where(["#{self.primary_key} < ?", version.is_a?(self) ? version.send(self.primary_key) : version]).order("#{self.primary_key} DESC")
|
||||
}
|
||||
|
||||
scope :following, lambda { |timestamp|
|
||||
|
@ -116,8 +116,8 @@ class Version < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def index
|
||||
id_column = self.class.primary_key
|
||||
sibling_versions.select(id_column.to_sym).order("#{id_column} ASC").map(&id_column.to_sym).index(self.send(id_column))
|
||||
id_column = self.class.primary_key.to_sym
|
||||
sibling_versions.select(id_column).order("#{id_column} ASC").map(&id_column).index(self.send(id_column))
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue