Skip to content

Commit

Permalink
Applying patch from 'Thorsten Buss'.
Browse files Browse the repository at this point in the history
Fixes issues in DboSource, where mismatching types on join columns could result in incorrect query generation.
Fixes #708
  • Loading branch information
markstory committed Dec 22, 2010
1 parent 5d2b4c7 commit 04929ae
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cake/libs/model/datasources/datasource.php
Expand Up @@ -503,6 +503,7 @@ function insertQueryData($query, $data, $association, $assocData, &$model, &$lin

foreach ($keys as $key) {
$val = null;
$type = null;

if (strpos($query, $key) !== false) {
switch ($key) {
Expand All @@ -526,13 +527,16 @@ function insertQueryData($query, $data, $association, $assocData, &$model, &$lin
$val = '';
}
}
$type = $model->getColumnType($model->primaryKey);
break;
case '{$__cakeForeignKey__$}':
foreach ($model->__associations as $id => $name) {
foreach ($model->$name as $assocName => $assoc) {
if ($assocName === $association) {
if (isset($assoc['foreignKey'])) {
$foreignKey = $assoc['foreignKey'];
$assocModel = $model->$assocName;
$type = $assocModel->getColumnType($assocModel->primaryKey);

if (isset($data[$model->alias][$foreignKey])) {
$val = $data[$model->alias][$foreignKey];
Expand Down Expand Up @@ -561,7 +565,7 @@ function insertQueryData($query, $data, $association, $assocData, &$model, &$lin
if (empty($val) && $val !== '0') {
return false;
}
$query = str_replace($key, $this->value($val, $model->getColumnType($model->primaryKey)), $query);
$query = str_replace($key, $this->value($val, $type), $query);
}
}
return $query;
Expand Down

0 comments on commit 04929ae

Please sign in to comment.