radar/paranoia — pull request #35 by arsduo (2012-11-21 18:47:59+00:00)
Title: Add support for dependent: :destroy! and :delete!

We've been using Paranoia in one of our projects at @6Wunderkinder, and it's been extremely useful. However, one gap we've found is that there are cases when you want to hard-destroy dependent resources -- for instance, when a user destroys her account, all related resources should be wiped from the database rather than left there orphaned.

This pull request adds support for `dependent: destroy!` (for HasOne and HasMany) and `dependent: delete!` (for HasOne -- delete_all for HasMany works out of the box). These options function as expected, calling callbacks or not and then hard-deleting the record.

This works for Rails 3.1 and 3.2 (tested with 3.1.8, 3.2.0, and 3.2.9). I started doing work on 3.0.x, but it turns out that the current version of Paranoia doesn't work with 3.0.x anyway -- ditto 4.0, which I may take a crack at later. (It's unfortunately involves copying some code from ActiveRecord, but it's relatively minimal (and should be less once paranoia is extended to cover Rails 4.0.)

Thanks for the great gem!