Commit 143f9847 by Erich Menge

Update_attribute is gone in Rails 4, add update_column support.

parent fa4d9c9b
...@@ -18,18 +18,25 @@ module Paranoia ...@@ -18,18 +18,25 @@ module Paranoia
end end
def delete def delete
self.update_attribute(:deleted_at, Time.now) if !deleted? && persisted? update_attribute_or_column(:deleted_at, Time.now) if !deleted? && persisted?
freeze freeze
end end
def restore! def restore!
update_attribute :deleted_at, nil update_attribute_or_column :deleted_at, nil
end end
def destroyed? def destroyed?
!self.deleted_at.nil? !self.deleted_at.nil?
end end
alias :deleted? :destroyed? alias :deleted? :destroyed?
private
# Rails 3.1 adds update_column. Rails > 3.2.6 deprecates update_attribute, gone in Rails 4.
def update_attribute_or_column(*args)
respond_to?(:update_column) ? update_column(*args) : update_attribute(*args)
end
end end
class ActiveRecord::Base class ActiveRecord::Base
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment