I have the beforeSave function in my model that hashes the password. I’m using transactions in my controller - which are dependent on the save of other models too.
My problem is that on the view page, the hashed password gets returned if the other models fail the transaction.
Any idea how I can trigger beforeSave only once the entire transaction has been committed?
Yes - the input is a passwordField. The problem is that the md5 hashed password is getting echoed back to that particular input if there is an error during the save of another model.
Your idea of unsetting the attribute in the exception gave me another idea. I assigned the original (non-md5) password to a variable, and just before the render - changed the $model->password to the original password. That way it does post the original password in the view, and saves the md5 password in the database.