Skip to content

Commit

Permalink
Update :has_many association declarations to use preferred scope bloc…
Browse files Browse the repository at this point in the history
…k syntax for rails4 and prevent deprecation warnings. Close #211
  • Loading branch information
Ben Atkins committed Mar 15, 2013
1 parent cb828d3 commit 009d3bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ def has_paper_trail(options = {})
self.versions_association_name = options[:versions] || :versions

has_many self.versions_association_name,
:class_name => version_class_name,
:as => :item,
:order => "#{PaperTrail.timestamp_field} ASC, #{self.version_key} ASC"
lambda { |_model| order(PaperTrail.timestamp_field.to_sym => :asc, _model.class.version_key.to_sym => :asc) },
:class_name => self.version_class_name, :as => :item

after_create :record_create, :if => :save_version? if !options[:on] || options[:on].include?(:create)
before_update :record_update, :if => :save_version? if !options[:on] || options[:on].include?(:update)
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/models/widget.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Widget < ActiveRecord::Base
has_paper_trail
has_one :wotsit
has_many :fluxors, :order => :name
has_many :fluxors, -> { order(:name) }
end

0 comments on commit 009d3bd

Please sign in to comment.