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

rebuild! if we migrate from another gem to closure_tree might ignore ordering #376

Open
krtschmr opened this issue Jan 27, 2021 · 0 comments

Comments

@krtschmr
Copy link

krtschmr commented Jan 27, 2021

coming from awesome_nested_set we use lft for ordering.
i checked the rebuild! method and it looks like it's calling children which then might be rendered randomly by our DB.
we then recreate the tree for each children, but this means that the position might change.

children.find_each { |c| c.rebuild!(true) }

https://github.com/ClosureTree/closure_tree/blob/07f4dfdac48765a60a786a5dfedaffb1d1e242be/lib/closure_tree/hierarchy_maintenance.rb#L65:L89

example

before:

1, lft: 1, position: nil
2, lft: 5, position: nil
3, lft: 4, position: nil
4, lft: 3, position: nil
5, lft: 2, position: nil

If we call .children we might get in return 1,2,3,4,5 but we actually want to get 1,5,4,3,2.

the tree then could be created like

1, lft: 1, position: 1
2, lft: 5, position: 2
3, lft: 4, position: 3
4, lft: 3, position: 4
5, lft: 2, position: 5
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