Disable beforeSave, afterSave etc on ->save()

I have something like this

$model=Policy::model()->findByPk($pk);

$model->name=‘1234’;

$model->save();

How can I disable beforeSave, afterSave etc on $model->save() ?

Why would you want to?




$model->saveAttributes(array('name' => '1234'));



API doc

Only been using Yii for about a week, but from what I’ve come across, saveAttributes() would save just what you want it to save.

To disable beforeSave, afterSave etc, I would imagine you override the methods within the model and not call the parent implementation.

From what I understand, those methods trigger other events, so I would make sure that is exactly what you want to do as there could be a cataclysmic ripple effect.

Nope. phtamas is right, take a look at the API.

Quote:

"saveAttributes() method … Saves a selected list of attributes. Unlike save, this method only saves the specified attributes of an existing row dataset and does NOT call either beforeSave or afterSave. Also note that this method does neither attribute filtering nor validation. "

For more details refer to saveAttributes

This disables validation, it doesn’t disable the hooks on saving (beforeSave and afterSave).

The right solution has already been posted.

1 Like