creocoder / yii2-nested-sets

The nested sets behavior for the Yii framework.
Other
446 stars 129 forks source link

Can get the Parents, but not the Childrens #109

Closed AlfioSaitta closed 7 years ago

AlfioSaitta commented 7 years ago

If i call the parents function, i can see the right result

Call: $net = ArrayHelper::toArray(User::findOne($this->id)->parents()->all());

Result:

[
    [
        'id' => 1,
        'username' => 'Alfio',
        'refer' => 0,
        'tree' => 1,
        'lft' => 1,
        'rgt' => 550,
        'depth' => 0,
    ],
    [
        'id' => 2,
        'username' => 'Administrator',
        'refer' => 1,
        'tree' => 1,
        'lft' => 2,
        'rgt' => 549,
        'depth' => 1,
    ],
    [
        'id' => 3,
        'username' => 'Manager',
        'refer' => 2,
        'tree' => 1,
        'lft' => 3,
        'rgt' => 548,
        'depth' => 2,
    ],
]

But i don't have any results from Children call Call: $net = ArrayHelper::toArray(User::findOne($this->id)->children()->all());

AlfioSaitta commented 7 years ago

Ok, find a workaround with a dataProvider:

        $provider = new ActiveDataProvider([
            'query' =>  User::findOne($id)->children(),
            'pagination' => [
                'pageSize' => false,
            ],
        ]);

        foreach ($provider->models as $row) {
            $tmp = $this->reportForUser($row->id, $product);
        }