Skip to content

Parent not included with requests #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Rasmus-Bertell opened this issue Apr 10, 2025 · 1 comment
Open

Parent not included with requests #618

Rasmus-Bertell opened this issue Apr 10, 2025 · 1 comment

Comments

@Rasmus-Bertell
Copy link

I have this package installed alongside spatie/laravel-query-builder but trying to include the parent with the request does nothing. I opened a discussion on the Query Builder side, but it seems like this is a problem in nested set.

It seems like the problem stems from the fix to an earlier issue1. While this fix works it seems to have the unintended consequence of removing parent relationship when requesting it and it has led to confusion and multiple issues23.

I think this fix should be revisited and implemented such that it doesn't interfere with other features.

/**
* @return array
*/
protected function getArrayableRelations()
{
$result = parent::getArrayableRelations();
// To fix #17 when converting tree to json falling to infinite recursion.
unset($result['parent']);
return $result;
}

Footnotes

  1. Maximum function nesting level error #17

  2. The 'parent' relationship missing in Model toJson() #507

  3. ->with('parent') do not work #563

@Rasmus-Bertell
Copy link
Author

Just adding to this that trying the requests listed in #17 don't work with deeply nested data.

return Nested::defaultOrder()->get()->toTree();
return Nested::defaultOrder()->get([ 'id' ])->toTree();
return Nested::defaultOrder()->get([ 'id', '_lft', 'parent_id' ])->toTree();

These all result in the same error with current build of Nested Set.

~/Projects/minimal> http get --headers [Accept application/json] --allow-errors http://localhost:8000
╭───────────┬─────────────────────────────────────────────────────────────────────────────────────────────╮
│ message   │ Maximum stack depth exceeded                                                                │
│ exception │ InvalidArgumentException                                                                    │
│ file      │ /home/rasmus/Projects/minimal/vendor/laravel/framework/src/Illuminate/Http/JsonResponse.php │
│ line      │ 89                                                                                          │

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant