Wednesday, October 24, 2012

Re: Copy branch of Tree to another parent

I guess nobody know of an easy way to do this?
nobody has ever written a routine to do this?
Last hope before I dive into this....
Thanks
Bill

On 10/22/2012 8:18 AM, Bill Stoltz wrote:
Sorry, if my question was not clear.

I want to "copy" the entire branch to another location.  So, if I want to copy a branch that has 5 children,
then I need to create the new parent node first, then once I have this ID, I can then create the 5 children nodes.
That is a fairly easy example.  But what about a branch that has 4 levels and 5 nodes? 

Is seems like I have to walk the original tree and create each node, then sub-node, then leaf, etc, etc.
Anyone done this before? Any suggestions?

Example - Before Copy
Root
|--Node1
|    |-- Node2
|    |-- Node3
|          |--Node4
|                |--Node5
|--Node6
     |--Node7

After Copy
Root
|--Node1
|    |-- Node2
|    |-- Node3
|          |--Node4
|                |--Node5
|--Node6
     |--Node7
          |--Node1
               |-- Node2
               |-- Node3
                     |--Node4
                           |--Node5

On 10/22/2012 12:27 AM, Jeremy Burns | Class Outfit [via CakePHP] wrote:
Surely you can just change the parent_id of the top of the branch you want to move? Then let the Tree behaviour take care of the rest.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 21 Oct 2012, at 23:24:53, bs28723 <[hidden email]> wrote:

Hi,
    I am using the tree behavior for one of my models, and I want to
copy a branch of a tree, with all the sub-branches, leafs etc to another
parent.
It looks like I am going to have to get a list of the children of the
copy from node, and then do a save for each new node.
would it work to do a find('threaded')  clear out all the parent_ids,
set the top node parent_id to the new parent_id, and do a save()?

Is there another way to do this?

Thanks,
bill



View this message in context: Copy branch of Tree to another parent
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 



If you reply to this email, your message will be added to the discussion below:
http://cakephp.1045679.n5.nabble.com/Copy-branch-of-Tree-to-another-parent-tp5711875p5711880.html
To start a new topic under CakePHP, email [hidden email]
To unsubscribe from CakePHP, click here.
NAML




View this message in context: Re: Copy branch of Tree to another parent
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: