From 2e0339edcb65b2215d314d3e0f9ebc0a334e28be Mon Sep 17 00:00:00 2001 From: Stas Ladonenko Date: Mon, 28 Nov 2011 15:46:35 +0200 Subject: [PATCH 1/2] refactored update method update_attributes doesn't work for 1) not valid records 2) white listed att_accessible attributes --- lib/soft_destroyable.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/soft_destroyable.rb b/lib/soft_destroyable.rb index 8db2b60..58d1468 100644 --- a/lib/soft_destroyable.rb +++ b/lib/soft_destroyable.rb @@ -112,9 +112,10 @@ def destroy! def revive transaction do cascade_revive - update_hash = {:deleted_at => nil, :deleted => false} - update_hash[:revive_with_parent] = true if respond_to?(:revive_with_parent) - update_attributes(update_hash) + self.deleted_at = nil + self.deleted = nil + self.revive_with_parent = true if respond_to?(:revive_with_parent) + save(:validate => false) end end @@ -150,7 +151,9 @@ def non_restrict_dependencies def soft_destroy transaction do cascade_soft_destroy - update_attributes(:deleted_at => Time.now, :deleted => true) + self.deleted_at = Time.now + self.deleted = true + save(:validate => false) end end @@ -161,7 +164,7 @@ def cascade_soft_destroy if assoc_obj.deleted? && assoc_obj.respond_to?(:revive_with_parent?) # if assoc_obj already deleted, and we are cascading a delete, just update the attribute revive_with_parent to false # so we know not to revive this object on a cascade of revive - assoc_obj.update_attributes(:revive_with_parent => false) + assoc_obj.update_attribute(:revive_with_parent, false) else assoc_obj.destroy end @@ -258,7 +261,7 @@ def handle_nullify(reflection, association) reflection.primary_key_name, reflection.dependent_conditions(self, self.class, nil)) when :has_one - association.update_attributes(reflection.primary_key_name => nil) + association.update_attribute(reflection.primary_key_name, nil) else end From 785d6b6ad4d2a4a896e84dc574582bf56e211f32 Mon Sep 17 00:00:00 2001 From: Stas Ladonenko Date: Thu, 15 Dec 2011 13:03:01 +0200 Subject: [PATCH 2/2] set deleted to false on revive --- lib/soft_destroyable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/soft_destroyable.rb b/lib/soft_destroyable.rb index 58d1468..4428f52 100644 --- a/lib/soft_destroyable.rb +++ b/lib/soft_destroyable.rb @@ -113,7 +113,7 @@ def revive transaction do cascade_revive self.deleted_at = nil - self.deleted = nil + self.deleted = false self.revive_with_parent = true if respond_to?(:revive_with_parent) save(:validate => false) end