mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Applying patch from 'Thorsten Buss'.
Fixes issues in DboSource, where mismatching types on join columns could result in incorrect query generation. Fixes #708
This commit is contained in:
parent
5d2b4c758d
commit
04929ae1df
1 changed files with 5 additions and 1 deletions
|
@ -503,6 +503,7 @@ class DataSource extends Object {
|
||||||
|
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$val = null;
|
$val = null;
|
||||||
|
$type = null;
|
||||||
|
|
||||||
if (strpos($query, $key) !== false) {
|
if (strpos($query, $key) !== false) {
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
|
@ -526,6 +527,7 @@ class DataSource extends Object {
|
||||||
$val = '';
|
$val = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$type = $model->getColumnType($model->primaryKey);
|
||||||
break;
|
break;
|
||||||
case '{$__cakeForeignKey__$}':
|
case '{$__cakeForeignKey__$}':
|
||||||
foreach ($model->__associations as $id => $name) {
|
foreach ($model->__associations as $id => $name) {
|
||||||
|
@ -533,6 +535,8 @@ class DataSource extends Object {
|
||||||
if ($assocName === $association) {
|
if ($assocName === $association) {
|
||||||
if (isset($assoc['foreignKey'])) {
|
if (isset($assoc['foreignKey'])) {
|
||||||
$foreignKey = $assoc['foreignKey'];
|
$foreignKey = $assoc['foreignKey'];
|
||||||
|
$assocModel = $model->$assocName;
|
||||||
|
$type = $assocModel->getColumnType($assocModel->primaryKey);
|
||||||
|
|
||||||
if (isset($data[$model->alias][$foreignKey])) {
|
if (isset($data[$model->alias][$foreignKey])) {
|
||||||
$val = $data[$model->alias][$foreignKey];
|
$val = $data[$model->alias][$foreignKey];
|
||||||
|
@ -561,7 +565,7 @@ class DataSource extends Object {
|
||||||
if (empty($val) && $val !== '0') {
|
if (empty($val) && $val !== '0') {
|
||||||
return false;
|
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;
|
return $query;
|
||||||
|
|
Loading…
Add table
Reference in a new issue