Permalink
Browse files

Fix SQL errors in TreeBehavior.

SQL errors were caused by escapeField() usage in TreeBehavior. Quoted
fields were not correctly unquoted.

Fixes #3491
  • Loading branch information...
1 parent bd69979 commit 965f0e87c5ddd29c020f77879015cac9a96f2410 @markstory markstory committed Dec 27, 2012
@@ -286,9 +286,14 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
$fieldAlias = $this->name($alias . '__' . $fields[$i]);
} else {
$build = explode('.', $fields[$i]);
- $this->_fieldMappings[$build[0] . '__' . $build[1]] = $fields[$i];
- $fieldName = $this->name($build[0] . '.' . $build[1]);
- $fieldAlias = $this->name(preg_replace("/^\[(.+)\]$/", "$1", $build[0]) . '__' . $build[1]);
+ $build[0] = trim($build[0], '[]');
+ $build[1] = trim($build[1], '[]');
+ $name = $build[0] . '.' . $build[1];
+ $alias = $build[0] . '__' . $build[1];
+
+ $this->_fieldMappings[$alias] = $name;
+ $fieldName = $this->name($name);
+ $fieldAlias = $this->name($alias);
}
if ($model->getColumnType($fields[$i]) == 'datetime') {
$fieldName = "CONVERT(VARCHAR(20), {$fieldName}, 20)";
@@ -248,7 +248,10 @@ public function testNoAmbiguousColumn() {
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
- $data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
+ $data = $this->Tree->find('first', array(
+ 'conditions' => array($modelClass . '.name' => '1. Root'),
+ 'recursive' => -1
+ ));
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));

0 comments on commit 965f0e8

Please sign in to comment.