I'm having an issue with Cake's Tree behavior, specifically setting a
scope. 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 uses tree behavior to manage ordering and
hierarchy. Now, obviously, I want completely separate hierarchies for
each NavList. So, when initializing the Tree behavior I do this:

class NavItem {
   var $actAsAs = array('Tree' => array('scope' => 'NavList'));
   ...
}

Even though the scope option of the Tree behavior 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 association scope. 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 of scope would 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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to