Answer the question
In order to leave comments, you need to log in
How to update in Yii without foreach for all models, the result of a find..() selection?
Good afternoon,
I have an array of descendant models:
$category=Category::model()->findByPk(1);
$descendants=$category->descendants()->findAll();
Answer the question
In order to leave comments, you need to log in
Don't write find at all then and don't work with the Category model. Work with the model you are going to update.
I can guess something like this:
If you want to update the array of selected ARs and do not want to write foreach to any, then you can use array_walk php.net/manual/en/function.array-walk.php
If I understand correctly, then try this:
$category=Category::model()->findByPk(1);
$descendants=$category->descendants()->findAll();
$ids = array_map(function($descendant) {
return $descendant->id;
}, $descendants);
Category::model()->addInCondition('id', $ids)->updateAll(array('exist' => 0));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question