I have a user model on which I check to make sure that the email address supplied is unique:
validates_uniqueness_of :email
This model acts as paranoid. On destroy, I need to remove the email address so that if the user wants to re-register, they can. For this, I have the following:
before_destroy :remove_email
def remove_email
self.email = "[deleted]"
save(false)
end
The method is called at the appropriate time, but the save method throws the following error:
ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '[deleted]' for key 2: UPDATE `users` SET `email` = '[deleted]', `updated_at` = '2009-07-16 12:29:05' WHERE `id` = 53
So it looks like the validation is still being run at some level. Is there any way of getting around this?