I want to update the data in the table via Actite Record . How to write a simple SQL query I know, the task is to use AR. We update one field; in the other, we calculate a new value. The problem is exactly how to describe the expression [current value + some number].
// $oldID - старый ID группы // $newID - новый ID группы // $delta - некое число, которое нужно прибавить к значению поля in_group // Код, который не работает Item::updateAll([ 'id_group' => $newID, 'in_group' => '[[in_group]] + $delta', ], ['=', 'id_group', $oldID]); The updateAllCounters () and updateAll () methods will not work separately due to restrictions in the database: the id_group and in_group pair is a unique key, so if you update, then at the same time.
UPD. There is an option using yii \ db \ Expression :
// Код, который работает Item::updateAll([ 'id_group' => $newID, 'in_group' => new Expression("in_group + {$delta}"), ], ['=', 'id_group', $oldID]); - but he does not like me. Can I do without Expression ?