D
D
Dmitry Petrik2016-03-24 15:03:40
Yii
Dmitry Petrik, 2016-03-24 15:03:40

Yii2. How to change the value of an attribute for all records in a table?

I do like this:

$models = Table::findAll(['type'=>$type]);
        foreach ($models as $model) {
            $model->value = 0;
            $model->save();
        }

But it reeks of some kind of bullshit. Too many requests if there are many entries. Is there any way to optimize?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
enchikiben, 2016-03-24
@Flexo

from off. docs www.yiiframework.com/doc-2.0/yii-db-activerecord.h ...

Customer::updateAll(['status' => 1], 'status = 2');

D
Dmitry Bay, 2016-03-24
@kawabanga

Throw a simple PDO request for Update

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question