On Sun, Jan 16, 2011 at 8:23 AM, gilsilas <[email protected]> wrote: > hey, > > I have comments table : > [ id , post_id, parent_id, lft, rght ] > > when I want to select data I select with threaded option limit by > post_id, and indeed I can see the tree for the certain post > > but in the comments table it seems like I have one tree for all > comments, so every time I do MoveUp,MoveDown etc... all the comments > table been manipulated and not only the certain post tree as I want. > > In addition, it's take longer to manipulate branch on tree with 50000 > rows ( when no limit by post_id ) vs manipulate branch to small tree > when limit by post_id. > > > How can I separate the comments table to several trees, which tree > under his post_id ?
Use the undocumented 'scope' option: http://api.cakephp.org/view_source/tree-behavior/#line-61 http://www.mcfarren.org/CodeCakePHPStoringMultipleTreesWithTreeBehavior There are several other ways to go about this, also. Here's an example from a Comments plugin I wrote, where a Comment may belong to one or more models. This method is in the Comment model. public function threaded($model_name = null, $key = null) { if (!$key || is_null($model_name)) return null; $filters = array( 'conditions' => array( $this->alias.'.model' => Inflector::camelize($model_name), $this->alias.'.foreign_key' => $key ), 'fields' => array('*'), 'order' => array($this->alias.'.lft' => 'ASC'), 'contain' => array( 'User' => array( 'fields' => array('User.id', 'User.name') ) ) ); $data = $this->find('threaded', $filters); return $data; } Also have a look at these Bakery articles: http://bakery.cakephp.org/articles/cyberthom/2010/01/27/multitree-behavior http://bakery.cakephp.org/articles/busytoby/2010/01/05/btree-behavior (note the second article is a 2-pager) Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
