Skip to content

Commit

Permalink
Fix SQL errors in TreeBehavior.
Browse files Browse the repository at this point in the history
SQL errors were caused by escapeField() usage in TreeBehavior. Quoted
fields were not correctly unquoted.

Fixes #3491
  • Loading branch information
markstory committed Dec 27, 2012
1 parent bd69979 commit 965f0e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -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)";
Expand Down
5 changes: 4 additions & 1 deletion lib/Cake/Test/Case/Model/Behavior/TreeBehaviorUuidTest.php
Expand Up @@ -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));
Expand Down

0 comments on commit 965f0e8

Please sign in to comment.