php-activerecord icon indicating copy to clipboard operation
php-activerecord copied to clipboard

Validations are run on clean attributes

Open koenpunt opened this issue 14 years ago • 6 comments

When I try to save my User model and do not pass the password to update_attributes, I'd expect the password to not be validated. But instead it tries to validate the hashed password which is stored in the database, which won't validate.

Is there a way to only validate attributes when they're dirty? And shouldn't this be the default behavior? Or has it be done using a custom validate function on the model?

koenpunt avatar Aug 27 '12 13:08 koenpunt

I am observing the same issue any suggestions?

tariq-mahmood-dev avatar Dec 16 '14 16:12 tariq-mahmood-dev

I believe this will be fixed when #464 lands

koenpunt avatar Dec 16 '14 16:12 koenpunt

can you please send me your fix. As I can't wait for that. My Email: [email protected]

tariq-mahmood-dev avatar Dec 16 '14 16:12 tariq-mahmood-dev

You can view the diff: https://github.com/jpfuentes2/php-activerecord/pull/464/files and download it as patch: https://github.com/jpfuentes2/php-activerecord/pull/464.patch or diff patch: https://github.com/jpfuentes2/php-activerecord/pull/464.diff

koenpunt avatar Dec 16 '14 16:12 koenpunt

Thanks koenpunt :)

tariq-mahmood-dev avatar Dec 16 '14 16:12 tariq-mahmood-dev

Koenpunt I made your changes in Model class, but still getting same issue. I am finding user by

$user = $this->model->find(array('conditions' => array('id = ?', $user_id))); then updating some attributes as: $user->first_name = $first_name; I am not changing value of password

Then $user->save(), returns validation error for password validation. Is there anything that I am missing?

just for record I am using 1.1-dev branch i.e. (https://github.com/jpfuentes2/php-activerecord/tree/1.1-dev)

tariq-mahmood-dev avatar Dec 17 '14 10:12 tariq-mahmood-dev