Skip to content

Commit

Permalink
Use new feature ActiveRecord::Base.suppress to handle new has_one beh…
Browse files Browse the repository at this point in the history
…aviour
  • Loading branch information
owenr committed Jan 13, 2016
1 parent 6c48103 commit 9de02cb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/paper_trail/reifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,13 @@ def reify_has_ones(transaction_id, model, options = {})
end
end

# Redefine #save on this instance as a no-op so we can reassociate with the
# reified master of a has_one relationship
# Suppress #save so we can reassociate with the reified master of a has_one relationship
def without_persisting(record)
record.instance_eval do
alias :actually_save :save
define_singleton_method(:save) { true }
if record.class.respond_to? :suppress
record.class.suppress { yield }
else
yield
end
yield
record.instance_eval { alias :save :actually_save }
end

# Restore the `model`'s has_many associations as they were at version_at
Expand Down

0 comments on commit 9de02cb

Please sign in to comment.