S
S
Sergey Melnikov2017-02-26 09:41:21
Yii
Sergey Melnikov, 2017-02-26 09:41:21

How to update a record in a model without calling before save?

How to do this in Yii2?
$data = Cars::find()->where(['id_car' => 100])->one();
$data >car_price = 150;
$data>save(false);
But so that there is no call to before save in the model.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-02-26
@webinar

$data >save(false);
this is saving without validation, before save will still work.
If you need to bypass before save and other events, then you should do this:
www.yiiframework.com/doc-2.0/yii-db-activerecord.h...

L
Lander, 2017-02-26
@usdglander

I didn’t quite understand: you already have an overridden beforeSave in the model with some kind of logic and you just need to turn it off in one place?
upd: If so, add the useBeforeSave flag to the model and check if (!$this->useBeforeSave) { return true; } at first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question