MPTtree, Hieararchical trees in a database table |
[eluser]renownedmedia[/eluser]
I will def be considering this class for a pyramid type affiliate based eCommerce application.
[eluser]crises[/eluser]
I finally found a way of doing a collapsible tree menu from data stored in this way (in my case categories of products for an online catalog). But now i would like to know if this solution is efficient. In my app i have categories stored as: Code: +Root ![]() To the point. In my catalog controller: Code: function category($current_category_url = null, $page=null) And the functions in the model (Catalog_model): Code: function get_current_category($category_url)
[eluser]iDenta[/eluser]
How do i get has_children() to work? The documentation doesn't cover has_children() much, but i've tried $this->MPTtree->has_children($root['lft'],$root['rgt']) and so on but it just returns "Call to undefined method MPTtree::has_children()"
[eluser]Mahmoud M. Abdel-Fattah[/eluser]
does anyone has an answer to this topic : http://ellislab.com/forums/viewthread/128614/
[eluser]TheFuzzy0ne[/eluser]
has_children doesn't seem to exist at the moment, even though it's documented. You need to be using hasChildren() for the interim.
[eluser]ntheorist[/eluser]
I found an interesting article regarding nested sets: http://explainextended.com/2009/09/29/ad...ets-mysql/ apparently you can speed up access of nested set queries by defining the left & right columns as spatial indexes. Any thoughts on how difficult it would be to implement this? Also the idea of also recording a level column for cases when adjacency-type queries would be faster is interesting. _n
[eluser]m4rw3r[/eluser]
Looks really interesting, bookmarking that article for later use when I create a plugin for RapidDataMapper (will be a switch or something, because not all uses MySQL). It does not seem to be too hard to implement, but I haven't tried it and it was a long time since I worked with the details of MPTT.
[eluser]nardanadam[/eluser]
Thank you for the mptt class firstly. As the documentation of MPTtree says: * When someone deletes a node which has subnodes, those connections must be re-established to another node. * It takes many querys to get all descendants or parents for a given node, in Nested Sets it takes only one. * You have two columns with the same data (id and parent_id). According to this disadvantages of mptt, I wonder how can I write the implementation of hierarchical(threaded or nested) comment system. As comments may have children comments and children have the parent comment. Because adding, deleting and editing the comment are available for user, I think mptt would be not a right choice. So any ideas for a situation like mine? My regards
[eluser]m4rw3r[/eluser]
If you need a tree something like this: Code: comment 1 Then maybe consider storing an order and a depth value, that will make it easy to do inserts (but it still needs locking as you have to make place for the new node). Code: order depth id other data... There are many ways to store a tree in a database, the hard thing is to find the most effective solution to the situation. MPTT is great if you're going to traverse the tree, but it isn't great if you just move one level at a time or move things in the tree very frequently.
[eluser]nardanadam[/eluser]
m4rw3r, your solution requires update of 'order' columns of data, when an insert operation is processed. Do you think it really fits for this situation? |
Welcome Guest, Not a member yet? Register Sign In |