![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
howdy, Nested sets (or modified preorder tree transversal algorithm) work great if a specific node only exists once inside the tree. I am using my tree for user authentication. For example, a group may have users and other groups in them. If the root groupA has groupB and groupC in it, and groupB contains groupC then groupC exists twice in the tree. Now, my issue is when I remove a subnode from groupC I need to remove that subnode from every instance of groupC in the root tree. This can become a nightmare of recursive functions (my reason for going with nested sets was to avoid recursive functions). |
#3
| |||
| |||
|
|
Sorry, but I do not quite see the problem. as a tree structure isn't it equivalent to this image? groupA +- groupB +- groupC In words: groupA is the parent of groupB which is the parent of groupC Why would groupC exist twice? Ed |
#4
| |||
| |||
|
|
Ed Prochak wrote: Sorry, but I do not quite see the problem. as a tree structure isn't it equivalent to this image? groupA +- groupB +- groupC In words: groupA is the parent of groupB which is the parent of groupC Why would groupC exist twice? Ed The full tree in my example would look something like this: groupA groupC -+- groupB +- groupC Because groupC exists in groupA and in groupB. So, when I add a fourth group into groupC it would need to be added twice into this tree. This may be what I need to do, but I am just checking to see if there is a more efficient way to do it (somehow adding groups by reference or something...). thanks for the reply! That's not really a tree. You've forced it to exist in tree form, but |
|
| +---B---+ |
#5
| |||
| |||
|
|
That's not really a tree. You've forced it to exist in tree form, but the node C logically has two parents, A and B: A--+-------+--C | | +---B---+ In a tree, nodes can only have 1 parent. If you're trying to model generalized groups like these, trees are the wrong model. In sql terms, a better model would be a users table, a groups table, users_contained table, and a groups contained table. |
#6
| |||
| |||
|
|
Bob Stearns wrote: That's not really a tree. You've forced it to exist in tree form, but the node C logically has two parents, A and B: A--+-------+--C | | +---B---+ In a tree, nodes can only have 1 parent. If you're trying to model generalized groups like these, trees are the wrong model. In sql terms, a better model would be a users table, a groups table, users_contained table, and a groups contained table. That makes since. It always seemed like a hack to think of it they way I was doing it. My goal is to get all of the user keys out of the group even if those users are in nested groups in one select. Could you give me an example of a select using the users_contained and groups_contained tables that would do this? Thanks! It actually takes four deletes: all C's users from users_contained; all |
#7
| |||
| |||
|
|
Bob Stearns wrote: That's not really a tree. You've forced it to exist in tree form, but the node C logically has two parents, A and B: A--+-------+--C | | +---B---+ In a tree, nodes can only have 1 parent. If you're trying to model generalized groups like these, trees are the wrong model. In sql terms, a better model would be a users table, a groups table, users_contained table, and a groups contained table. That makes since. It always seemed like a hack to think of it they way I was doing it. My goal is to get all of the user keys out of the group even if those users are in nested groups in one select. Could you give me an example of a select using the users_contained and groups_contained tables that would do this? |
![]() |
| Thread Tools | |
| Display Modes | |
| |