acts_as_tree vs ancestry gem for tree menu [closed]

对着背影说爱祢 提交于 2019-12-05 22:13:18

Use ancestry. It has more powerful query capabilities as it implements the materialized path pattern, as opposed to acts_as_tree that implements adjacency list.
There are other options too, like nested set, but materialized path is usually the most comprehensive.

https://communities.bmc.com/communities/docs/DOC-9902

If you need to sort in preorder at DB level (for example a paginated tree-grid, a preloaded menu that you iterate and indent/dedent according to the depth in tree for displaying) you need to either use a recursive query, or sortable encoding like nested set or nested interval. (That is if sorting in memory is not an option, and it almost never is.)

https://github.com/collectiveidea/awesome_nested_set
https://github.com/clyfe/acts_as_nested_interval

Each has ups and downs. Choose your what fits you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!