How to detect a destroyed model object

After I do x.destroy on AR descendant x, is there any method I can call on x to determine that it was destroyed.

x.new_record? returns false x.id returns the previous primary key (now gone since the destroy).

x.frozen?

I believe will return true if the object has been destroyed.

Philip Hallstrom wrote:

After I do x.destroy on AR descendant x, is there any method I can call on x to determine that it was destroyed.

x.new_record? returns false x.id returns the previous primary key (now gone since the destroy).

x.frozen?

I believe will return true if the object has been destroyed.

My testing shows that frozen? returns false.

I am on Rails 1.1.6 if that matters.

Strange. I am too and my test returned true.

x = MyModel.find(:first) x.destroy x.frozen?

yielded true.

This was via console...

Wes Gamble wrote:

That's right.

"Deleting" this object really means moving all of it's child data to archive tables and then marking it (the parent) as deleted.

*Don't ask - this is existing functionality from the system I'm integrating into.*

That's actually not that unusual. There's even a Rails plugin acts_as_paranoid that does a similar thing.

I use acts_as_paranoid, and it still freezes the object once you destroy it even though the row is not removed. You may want to add that to your overridden destroy to keep you from accidentally modifying your "deleted" items. It's simple to do, just call x.freeze and you are all set.

Wes Gamble wrote:

aap will do a volatile delete if you use the :destroy! method on the object.