Im creating form that inserts new set in db. And inserts it under the given parent id.
Im now in beforeSave() where I want other db entries to be updated.
protected function beforeSave()
{
if (parent::beforeSave()){
if($this->parent_id >= 0){
$parent = self::model()->findByPk($this->parent_id);
if($parent){
self::model()->updateAll(); // cant figure out how to use this as I need.
}else{
return false;
}
}
}
}
I think update all would be appropriate function here, but I need it to update every db entry
update nodes
where left > $parent->left to left = left + 2
update nodes
where right > $parent->right to right = right + 2
Here is CActiveRecord updateAll() reference:
http://www.yiiframework.com/doc/api/1.1/CActiveRecord#updateAll-detail
I want to do this not making many function calls. How can I do it?