Seriously? Nobody has experience with TreeBehavior's scope option?
On Sep 15, 1:45 pm, Jamie <[email protected]> wrote: > I'm having an issue with Cake'sTreebehavior, specifically setting ascope. > I've created a dynamic navigation system so that clients can > manage navigation lists and items via a CMS. The associations look > like this: > > NavList hasMany NavItem > NavItem belongsTo NavList > > Simple enough. NavItem usestreebehavior to manage ordering and > hierarchy. Now, obviously, I want completely separate hierarchies for > each NavList. So, when initializing theTreebehavior I do this: > > class NavItem { > var $actAsAs = array('Tree' => array('scope' => 'NavList')); > ... > > } > > Even though thescopeoption of theTreebehavior is woefully under- > documented, I found it by looking at the TreeBehavior class itself. > Basically, passing the alias of the model's associated belongsTo model > - so, passing NavList, since NavItem belongsTo NavList - sets up a > foreign key associationscope. As far as I can tell, this is so you > can maintain different hierarchies within the same table, which is > what I'm trying to do. The code in TreeBehavior::setup() looks like > this: > > if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) > { > $data = $Model->getAssociated($settings['scope']); > $parent =& $Model->{$settings['scope']}; > $settings['scope'] = $Model->alias . '.' . $data['foreignKey'] . ' = > ' . $parent->alias . '.' . $parent->primaryKey; > $settings['recursive'] = 0; > > } > > But the problem is, this breaks the SQL query. TreeBehavior::__getMax > () ends up generating this query: > > SELECT MAX(`rght`) AS `rght`, `NavItem`.`id` FROM `nav_items` AS > `NavItem` LEFT JOIN `nav_lists` AS `NavList` ON > (`NavItem`.`nav_list_id` = `NavList`.`id`) WHERE > `NavItem`.`nav_list_id` = `NavList`.`id` ORDER BY `NavItem`.`lft` > ASC LIMIT 1 > > which generates this error: > > *SQL Error:* 1140: Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) > with no GROUP columns is illegal if there is no GROUP BY clause > > It's strange that the intended effect ofscopewould break the query. > Anyone? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
