protected function isValidCode()
{
$parent = $this->parent;
if (!$parent) {
return true;
}
$find = $parent->getChildren()->where(["code" => $this->code, 'pid' => $this->pid]);
if (!$this->isNewRecord) {
$find->andWhere(["!=", 'id', $this->id]);
}
if ($find->one()) {
return false;
}
return true;
}