public function processNormalize()
{
//Если это новая несохраненная сущьность, ничего делать не надо
if ($this->isNewRecord) {
return $this;
}
if (!$this->pid) {
$this->setAttribute("dir", null);
$this->save(false);
} else {
$this->setAttributesForFutureParent($this->parent);
$this->save(false);
}
//Берем детей на один уровень ниже
if ($this->children) {
$this->save(false);
foreach ($this->children as $childModel) {
$childModel->processNormalize();
}
}
return $this;
}