Tuesday, December 3, 2013

Re: Posting to the top of the tree using the Tree Behavior

Of course, sorting it DESC makes perfect sense.  Just needed someone to get me out of the box.  Now I just need to reorder the data that's already there so when I do a DESC sort it stays the way it is now (only new records will be put at the top of the tree).  I think that's easily done.

Thanks.

On Tuesday, December 3, 2013 5:38:20 AM UTC-6, AD7six wrote:


On Monday, 2 December 2013 19:22:14 UTC+1, Justin Thomas wrote:
I'm using the Tree Behavior in one of my models.  When a new record is added by default it post the new record at the bottom of the tree.  What I need it to do is post the new record at the top of the tree. 

That will require updating every existing record in the table.
 
I've looked at the documentation and I don't see anything to change that default behavior. 
 
I also looked at the reorder method, but I'm unsure how to use that to move a new record to the top of the tree.

Reorder is not the method you need - moveUp is.


If I pass the lft and rght parameters as 1 and 2 will the other records update automatically? 

Nope
 
Any ideas on how to achieve this?

Try something =). Alternatively treat the tree inverted - i.e. don't do what you're asking but instead query the tree sorted by lft desc - the last created record would be first.

AD 

--
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 unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: