acts_as_tree vs ancestry gem for tree menu [closed]

≯℡__Kan透↙ 提交于 2019-12-07 18:21:28

问题


I want to implement a tree menu (simple example of tree menu) in a Rails app that I am working on. I am unsure of whether to use acts_as_tree or Ancestry. Its seems that it would be easier to implements a simple tree menu using acts_as_tree, however, Ancestry is more popular and regularly maintained. Does anyone have any thoughts on this?


回答1:


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.



来源:https://stackoverflow.com/questions/8835178/acts-as-tree-vs-ancestry-gem-for-tree-menu

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