| Nested Set [message #1850] |
Wed, 18 January 2006 12:49  |
joesimms Messages: 38 Registered: December 2005 |
Member |
|
|
I was just wondering if symfony included a class to easily manage a nested set, i think i came across one when i first downloaded the code but cannot seem to find it again anywhere. If there is a class available for this, is there any form of documentation / usage examples to be found anywhere, if there is not currently support ffor this, then are there any suggestions on how best to perform this without using the PEAR Nestedset class which will undermine the propel/creole component of symfony, and are there plans to include this in future releases?
Many thanks
|
|
|
| Re: Nested Set [message #2057 is a reply to message #1850 ] |
Tue, 24 January 2006 16:50   |
joesimms Messages: 38 Registered: December 2005 |
Member |
|
|
I cannot seem to find a class for managing nested sets and if there is no class available then i'd like to write one based upon similiar functionailty as outlined in the following article:
http://www.edutech.ch/contribution/nstrees/index.php
This seems fairly comprehensive and intuitive, i'm unsure if there are any other approaches other than PEAR's Nested Set.
With regards to the best way to design this class, i thought that it might be a good idea if it is considered at the model level of the framework. I am not sure whether this would be the best way or whether it would be possible, however I am suggesting the following:
In the schema.xml file you can identfy the table as a nested set (in a similiar way you can identify i18n tables). When the ORM is created, it still creates the same BaseArticle class with all the standard DA functionality as before, but with extended attributes and methods specific for nested set manipulation. This would then easily allow us to use this functionality within our actions and inline with using propel without having to rely on other DA protocols or direct access to the DB itself (as would be the case with using PEAR's package, this could be a limitation for those who don't want to use propel, but then they could always use PEAR's Nested Set I suppose).
Does anybody have any other suggestions / alternatives, or is it currently available somewhere within Symfony? Also, if this was deemed a good solution and i contributed the extended class functionality, would this be something that you would consider integrating into the framework? Further development would also allow the new admin generator to generate specific actions to manipulate the nested set, thus also automating this in the back office generation.
Thanks
|
|
|
|
|
| Re: Nested Set [message #5091 is a reply to message #1850 ] |
Tue, 18 April 2006 04:15   |
|
If there is no problem I encourage you to put it here, Im also interested in this matter
|
|
|
|
|
| Re: Nested Set [message #10264 is a reply to message #1850 ] |
Wed, 16 August 2006 22:42   |
joesimms Messages: 38 Registered: December 2005 |
Member |
|
|
Hi
Here is my implementation.
I have been working on this off list with Gregory Becker
The code seems to be fairly stable although not totally finished and tested, and lacks docs.
Gregory wrote a test module, and I have included some test data and a schema for you to play with, hope this helps.
FYI, I am working with the Propel Team at the moment to integrate this in Propel, so all you have to do is type
<table ... tree="nestedset">
and it will auto generate a TreePeer, and the convenience methods to the stub. I am very busy at the moment, but will post here when this has been done.
Also, you can see Gregorys previous version here, this is now decremented, but could be useful, but we have merged our code to provide this solution, which after some minor refactoring will integrate into Propel.
http://www.symfony-project.com/trac/wiki/HowToHandleHierarch icalDataWithPropel
Hope this helps
Thanks
Joe
PS Please note that when integrated into Propel, method names may change slightly, as may queries etc, so please view as a work in progress.
|
|
|
| Re: Nested Set [message #11570 is a reply to message #1850 ] |
Wed, 06 September 2006 14:17   |
donharold Messages: 99 Registered: May 2006 |
Member |
|
|
@joesimms
This looks very promising - any details on the propel integration? I follow the propel dev list, and from what I gather, the next point release is still a bit away, not to mention it will then have to be integrated into symfony.
Not that it matters much, as it's easy to use your existing solution.
While you're at it, I have a feature request that I think is quite important:
Right now, you can't store several independent trees in a single table, because the left and right greater that/less than checks might mix up tree nodes after adding and deleting a few nodes. So I think adding a namespace field to the table would be a good idea.
In practice you'd then for example call retrieveRoot($ns) instead of retrieveRoot(), and automagically work with the selected tree from there.
// edit:
After further looking through the code in the zip, I have another question: Wouldn't methods like MenuPeer::insertAsLastChildOf($dest, $node, $con = null) make more sense as instance methods of the $dest node?
Please don't take this as criticism, I'm just curious.
Thanks
[Updated on: Wed, 06 September 2006 14:28]
|
|
|
| Re: Nested Set [message #11573 is a reply to message #10264 ] |
Wed, 06 September 2006 14:39   |
|
@joesimms
Seems to be very interesting and the integration in Propel is clearly an advantage.
One suggestion if I could, I think that building the tree with a list (<ul><li>..) should be better, because it will produce a cleaner and more accessible HTML.
all about me
t-shirts
|
|
|
|
|
| Re: Nested Set [message #20630 is a reply to message #20261 ] |
Wed, 31 January 2007 08:59   |
pezetgee Messages: 734 Registered: March 2006 |
Faithful Member |
|
|
| mishal wrote on Tue, 23 January 2007 16:04 | [...] but i'm missing support for more than one root element - I don't know if is this possible. [...]
|
AFAIK there should be only one root element.
If you need to have more top level elements you could use root as their holder - not as the 'data element'
|
|
|
| Re: Nested Set [message #20634 is a reply to message #1850 ] |
Wed, 31 January 2007 10:31   |
|
I have used PEAR's nested set in the past and it supports more then one root element. I need to store culture in my nested_set table, and different culture needs different tree. Maybe it's bad database design 
|
|
|
| Re: Nested Set [message #20637 is a reply to message #20634 ] |
Wed, 31 January 2007 10:51   |
pezetgee Messages: 734 Registered: March 2006 |
Faithful Member |
|
|
hmm,
personnaly I would have one root and then cultures on the first level (just after root), but I haven't used PEAR's nested set before.
perhaps it's time to have a look at it..
[Updated on: Wed, 31 January 2007 10:51]
|
|
|
| Re: Nested Set [message #20641 is a reply to message #20637 ] |
Wed, 31 January 2007 11:12   |
|
I don't like PEAR's nested set class. It's quite old and the code is ugly.
I think nested set is really needed 
I tried also Propel Tree implementation, but i think it's not usable.
I'll have to switch back to parent_id and recursion ...
|
|
|
| Re: Nested Set [message #20643 is a reply to message #20641 ] |
Wed, 31 January 2007 11:21   |
pezetgee Messages: 734 Registered: March 2006 |
Faithful Member |
|
|
I have started work on the propel adjacency model module.
It's still in a very early stage.. I'll post the code when it's ready for testing (I estimate it will be in a couple of weeks - too busy right now with other stuff)
|
|
|
| Re: Nested Set [message #20645 is a reply to message #1850 ] |
Wed, 31 January 2007 11:27   |
|
Thanx, nice to hear this:)
Count on me with testing.
|
|
|
|
| Re: Nested Set [message #20651 is a reply to message #20648 ] |
Wed, 31 January 2007 11:39   |
|
Greeat! Multiple roots 
| Quote: |
The nested implementation can be configured to allow your table to have multiple root nodes, and therefore multiple trees within the same table.
|
Thanx chtito. I'm going to test Doctrine soon!
|
|
|
|
|
|
|
|
| Re: Nested Set [message #21320 is a reply to message #1850 ] |
Fri, 09 February 2007 13:34   |
|
This morning, on the Symfony Google user group, a post talk about Nested Set support in Propel.
It seems that complete support will require Propel 1.3.
So I'm wondering how to update propel in symfony (just replace propel folder in PEAR/Symfony/vendor ?) and if it might break something (other than things broken by the replacement of Creole by PDO) ?
[Updated on: Fri, 09 February 2007 13:42] all about me
t-shirts
|
|
|
|