Answer the question
In order to leave comments, you need to log in
Yii2 how to make a hole in model id?
Good day!
I am translating the application to yii2. The database has a "pipes" table that contains a list of products sorted by record id (for example:
1 | Thin hose
2 | Medium diameter hose
3 | Thick hose
)
Sometimes you need to add a few more records, bringing it to this form:
1 | Thin hose
2 | Thin reinforced hose
3 | Medium diameter hose
4 | Medium diameter hose, water/gas
5 | Thick hose
In the original, I made a sql query that "punched" a hole in the id list:
UPDATE TABLE `pipes` SET id=id+1 WHERE id > 2;
Is it possible to do the same in yii2 through models?
For example, this option:
$models = Pipes::find()->where("id > 2")->all();
foreach ($models as $model){
$model->id++;
$model->save();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question