Welcome Guest, Not a member yet? Register   Sign In
need help with datamapper orm and nestedsets
#11

[eluser]WanWizard[/eluser]
Ah, that root_id.

You only need that if you intend to store multiple trees in the same table (like for example menu structures), in which case you use the root_id (or whatever you named it) to select the tree you want. If you don't have multiple trees, you don't need that column (or the select_root() method call).

Sorry, I don't have any code examples for you, don't have any CI running anymore since 2010.

Yes, that seems to be the correct sequence of method calls.
#12

[eluser]kev[/eluser]
last question, everytime i create a new tree, am I supose to determine the new root_id by myself? or is it implemented?
#13

[eluser]WanWizard[/eluser]
No, you have to pick it yourself. Because it doesn't have to be an integer (we used to have menu names in there in one app), it's difficult to automatically determine the next value.

Code:
$tree = new Category();
$tree->select_root(2);  // create the second tree
$tree->new_root();
#14

[eluser]kev[/eluser]
Then I guess selecting the highest root_id in the table, then incrementing it by one might work! I will post the result once I'm done with it.
#15

[eluser]WanWizard[/eluser]
Yes but be careful for concurrency issues, two users could run a MAX query and insert a new tree at the same time resulting in duplicates.

I can vaguely remember we solved this in an app by having a unique index on root_id+left_id. You can determine the MAX in a loop, and when you create the new root for a root_id that was just created by someone else, you'll get a DB error, which you can capture, and loop to determine a new MAX value...
#16

[eluser]kev[/eluser]
I found a very strange problem.. I created two different Tree, "Tree 1", and "Tree 2".

Tree 1

root_id = 1
left_id = 1
right_id = 2

Tree 2

root_id = 2
left_id = 1
right_id = 2

I have one sub item under Tree 1 and nothing under Tree 2.. But why is the output like this? See below :

Code:
"Tree 1"
    "Tree 2"
        "Sub Tree 1"

Shouldn't it be like this :

Code:
"Tree 1"
    "Sub Tree 1"
"Tree 2"

??

I'm running this code

Code:
echo $tree->dump_tree( array('title'), 'html' , FALSE );

Please help me fix this output Sad
#17

[eluser]kev[/eluser]
Is this a known bug of the nested set extension?
#18

[eluser]CroNiX[/eluser]
I use nested sets a lot, but not this implementation. From what I can see from your example, nothing in tree 2 should have the same left/right ids as those in tree 1. They are different, separate trees. Trees don't share branches with other trees. Since they are in this case, it's making it a single tree in the output because the left/right IDs from tree 2 fall within those of tree 1. To build a tree, you are saying "give me everything that has a left id between the left and right id of the root node". How is it supposed to do that, and keep them separate, if the nodes left/right ids are the same for both trees?
#19

[eluser]kev[/eluser]
OK that makes sense, but how do i create a new tree that won't mess up everything using this extension? Any idea?

I want to achieve something like this.

Code:
"Tree 1"
    "Sub 1"
"Tree 2"
    "Sub Tree 2"
"Tree 3"
"Tree 4"

This extension supports multiple trees.

How can I overcome this?
#20

[eluser]CroNiX[/eluser]
I'm sorry, I haven't used this extension and don't want to mislead you. I may already have as I didn't realize this supports multiple trees, which might allow for using the "same left/right ids" in both trees because I assume there is also a "tree id", which might be the "root_id" in this case. If there was a unique tree id, I could see being able to have left/right ids that are common because they point at different trees. Again, I don't know and I'm sorry if I did mislead you here. I'm used to working with one tree at a time. I'm sure WW will chime in.

I use separate tables for separate trees as each tree deals with different types of hierarchical data.




Theme © iAndrew 2016 - Forum software by © MyBB