Answer the question
In order to leave comments, you need to log in
How to hide a tree branch in Yii, with unlimited nesting of descendants?
Good afternoon,
there is a table in a DB where records have an unlimited nesting.
How to get a list of elements, without descendants, descendants of descendants, descendants of descendants...etc.
Getting without descendants is pretty easy $model->findAll('parent_id !='.$id);
. But how to exclude all descendants?
Needed for editing so that the element's parent cannot be one of its children.
Answer the question
In order to leave comments, you need to log in
Here is the solution
Model:
public function exceptChild($data,$rootID){
foreach($data as $id => $node){
if($node->parent_id == $rootID){
unset($data[$id]);
$data = $this->exceptChild($data,$node->id);
}
}
return $data;
}
$data = $model->exceptChild($model->findAll('id !='.$id),$id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question