Skip to content
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

Fixes incorrect order of nested items when item is more than 2 levels deep #2388

Merged
merged 2 commits into from
Jan 10, 2024

Conversation

pauldwight
Copy link
Contributor

@pauldwight pauldwight commented Jan 3, 2024

Incorrect order of nested items when item is more than 2 levels deep.

Description

The getAncestors() from the nestedset package doesn't set any default order which means that the ancestors returned are in order of creation (id) rather than hierarchical order.

Rather than making the assumption as to what order the ancestor items were created it is better to sort the collection by the _lft column (as the defaultOrder() method does in the package).

See https://github.com/lazychaser/laravel-nestedset#ancestors-and-descendants for more info.

Related Issues

Fixes #2387 #2302 #2280

Copy link
Member

@ifox ifox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pauldwight, really appreciate you jumping on this!

This looks like the appropriate solution, just made a minor suggestion.

I looked at the history of this method and it looks like we got it wrong a couple of times and that the confusion came from the fact that it used to depend on the order of record creation.

src/Models/Behaviors/HasNesting.php Outdated Show resolved Hide resolved
@pauldwight pauldwight requested a review from ifox January 10, 2024 10:27
@ifox ifox merged commit 1fcc8f3 into area17:3.x Jan 10, 2024
10 of 11 checks passed
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

Successfully merging this pull request may close these issues.

$item->ancestorsSlug returns items in reverse order? Issue with HasNesting trait
2 participants