Jump to content

Nested Sets - updating/moving nodes and their child nodes too


Lykos22

Recommended Posts

Hi, I'd like some help please.

 

I'm trying to create the functionality for managing menu items, using nested sets. So far I have created the functionality for adding new nodes/menu items and also deleting them and works fine (INSERTING and DELETING).

 

My problem is that I can't figure out how to do the UPDATE, i.e to move a node and its child nodes (if any) and set it as a child node, change the node/menu items order of display etc etc.

 

I did a research on google, but wasn't friendly enough, perhaps I used and wrong keywords. Adnyway does anyone knows what pseudo - sql queries I must use and the logic in order to update nodes?

 

thanks in advance

Edited by Lykos22
Link to comment
Share on other sites

What do you have so far, what database structure have you set up?

Yes I have set up my database like this

id (pk)menu_itemparent_id lftrgt

and I have also created the functionality for adding nodes/menu items and deleting them.

 

Now I'd like to do the update functionality, where basicly I can move nodes (and their child nodes too if any) everywhere inside the tree. for that I'm planning to use the nestedSortable plugin ( http://mjsarfatti.com/sandbox/nestedSortable/ ).

 

Ijust can't figure out the "update nodes" logic, you know, what steps I should follow to do that. Could you give me some pseudo - sql queries that are used for this functionality?

Link to comment
Share on other sites

It seems like moving a node would just mean changing the parent ID, right? So just a basic update query to update the parent ID would do it.

 

No I'm afraid you 're probably refering to the adjaceny model. I use the nested sets model ( mptt ). This link explains each one pretty well.

 

I would also have to change and the left (lft) and right (rgt) values not only from the node selected, but from the rest of the nodes of the tree too.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...