Thursday, April 10, 2008

cracks in acts_as_paranoid

This may be my first rails blog entry. It's born out of pure frustration. :)

When you destroy an activerecord object that uses acts_as_paranoid, the record is flagged instead of actually deleted. You can then look at the database and review those deleted items. Combined with acts_as_audited you get an interesting audit trail.

acts_as_paranoid monkeys with AR to pull this off. Unfortunately there are times when cracks show through.
  1. When you call find, do not use :include to join in a paranoid model unless you make arrangements to drop out deleted records
  2. If you want to use a :through relation with a paranoid model, you must add a clause to drop deleted records.
The latter you do with something like:
has_many :movies, :through => :dancer_movies, :conditions => ['dancer_movies.deleted_at is null']
I'll add more as I discover them.

No comments: