ActsAsParanoid / acts_as_paranoid

ActiveRecord plugin allowing you to hide and restore records without actually deleting them.
MIT License
1.46k stars 191 forks source link

Honor foreign key constraint violation #254

Closed benoittgt closed 2 years ago

benoittgt commented 2 years ago

Hello

This is not an issue but more a feature request and a discussion.

I have a table with a foreign key constraint to another table entry. The problem is acts_as_paranoid skips constraint CHECK because destroyed record are only updated.

I would like to know if it could be a good idea to add an option to delete and rollback the transaction and properly raise the foreign key constraint violation if there is one.

So still soft delete + raise on FK constraint violation.

turnon commented 2 years ago

You mean raise error when dependent: :restrict_with_exception detected ?

class Author < ActiveRecord::Base
  acts_as_paranoid
  has_many :posts, dependent: :restrict_with_exception
end

author.destroy # => raise error
benoittgt commented 2 years ago

@turnon completely !

Thanks