I have a single table of categories with joins to itself to allow me to create subcategories. Active Record models are working just fine, so that I am able to do this:
$categories = Category::find()->where(['name' => 'Root'])->with('children')->asArray()->one();
That gets me one level deep of children. If my categories are 3 levels deep (for example), I have to do something like this:
$categories = Category::find()->where(['name' => 'Root'])->with('children.children.children')->asArray()->one();
This works just fine and gets me what I need. What I really would like though, is to not have to repeat the word children (as in, “children.children.children”) because I don’t want to have to know or consider ahead of time how deep the category tree might be.
Is there a way to make this work so that I don’t have to know the depth of the tree ahead of time, and also so that I don’t have to do children.children.children.children.children.children if the tree happens to nest 6 levels?