Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/soft_destroyable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = false
self.revive_with_parent = true if respond_to?(:revive_with_parent)
save(:validate => false)
end
end

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down