From 04929ae1df80420bb53d6257c6125e3fe51ca70d Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 21 Dec 2010 20:40:19 -0500 Subject: [PATCH] Applying patch from 'Thorsten Buss'. Fixes issues in DboSource, where mismatching types on join columns could result in incorrect query generation. Fixes #708 --- cake/libs/model/datasources/datasource.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index 94b5d5cef..5de46be8a 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -503,6 +503,7 @@ class DataSource extends Object { foreach ($keys as $key) { $val = null; + $type = null; if (strpos($query, $key) !== false) { switch ($key) { @@ -526,6 +527,7 @@ class DataSource extends Object { $val = ''; } } + $type = $model->getColumnType($model->primaryKey); break; case '{$__cakeForeignKey__$}': foreach ($model->__associations as $id => $name) { @@ -533,6 +535,8 @@ class DataSource extends Object { 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]; @@ -561,7 +565,7 @@ class DataSource extends Object { 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;