#5772: Invalid query generated by TreeBhavior::verify() when using
TreeBehavior::reorder() inside a controller.
-------------------------------+--------------------------------------------
Reporter: sebby | Type: Bug
Status: new | Priority: High
Milestone: 1.2.x.x | Component: Behaviors
Version: RC3 | Severity: Normal
Keywords: | Php_version: PHP 4 >= 4.3.2
Cake_version: 1.2.0.7692 RC3 |
-------------------------------+--------------------------------------------
When I'm using the following MySQL table/data to store my categories using
the tree behavior:
{{{
CREATE TABLE `categories` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`parent_id` INT(10) UNSIGNED DEFAULT NULL,
`left` INT(10) UNSIGNED DEFAULT NULL,
`right` INT(10) UNSIGNED DEFAULT NULL,
`name` VARCHAR(100) NOT NULL DEFAULT '',
`created` DATETIME DEFAULT NULL,
`modified` DATETIME DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`),
KEY `left` (`left`),
KEY `right` (`right`),
KEY `name` (`name`),
KEY `created` (`created`),
KEY `modified` (`modified`)
) ENGINE=MyISAM;
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(1, 'My Categories', NULL, 1, 30);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(2, 'Fun', 1, 2, 15);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(3, 'Sport', 2, 3, 8);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(4, 'Surfing', 3, 4, 5);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(5, 'Extreme knitting', 3, 6, 7);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(6, 'Friends', 2, 9, 14);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(7, 'Gerald', 6, 10, 11);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(8, 'Gwendolyn', 6, 12, 13);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(9, 'Work', 1, 16, 29);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(10, 'Reports', 9, 17, 22);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(11, 'Annual', 10, 18, 19);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(12, 'Status', 10, 20, 21);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(13, 'Trips', 9, 23, 28);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(14, 'National', 13, 24, 25);
INSERT INTO `categories` (`id`, `name`, `parent_id`, `left`, `right`)
VALUES(15, 'International', 13, 26, 27);
}}}
and the associated model (/app/models/category.php):
{{{
<?php
class Category extends AppModel {
public $name = 'Category';
public $actsAs = array(
'Tree' => array(
'left' => 'left',
'right' => 'right'
)
);
}
?>
}}}
and controller (/app/controllers/categories_controller.php):
{{{
<?php
class CategoriesController extends AppController {
public $name = 'Categories';
public function index() {
debug($this->Category->generateTreeList(null, null, null,
' '));
}
public function reorder() {
$this->Category->reorder();
debug($this->Category->generateTreeList(null, null, null,
' '));
}
}
?>
}}}
I'm getting a MySQL syntax error generated by the following query (when
using TreeBehavior::reorder() method inside reorder action of categories
controller):
{{{
SELECT COUNT(*) AS `count` FROM `categories` AS `Category` WHERE 1 = 1 AND
`Category`.`left`< 1 AND right> 30
}}}
From my searches the conditions used for this query can be found inside
/cake/libs/model/behaviors/tree.php at line 769 (inside
TreeBhavior::verify())
A suggested patch for this problem is to replace line 769:
{{{
} elseif ($model->find('count', array('conditions'
=> array($scope, $model->escapeField($left) . '< ' .
$instance[$model->alias][$left], $right . '> ' .
$instance[$model->alias][$right]), 'recursive' => 0))) {
}}}
with this one:
{{{
} elseif ($model->find('count', array('conditions'
=> array($scope, $model->escapeField($left) . ' < ' .
$instance[$model->alias][$left], $model->escapeField($right) . ' > ' .
$instance[$model->alias][$right]), 'recursive' => 0))) {
}}}
Thanks!
--
Ticket URL: <https://trac.cakephp.org/ticket/5772>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets 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/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---