From 10ad71b30c3439826a32246781b18fcdf173d361 Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 14 Sep 2006 02:11:38 +0000 Subject: [PATCH] Adding fix for association query when the association has a null value for a FK git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3473 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/datasource.php | 3 +++ cake/libs/model/datasources/dbo_source.php | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index e5f8b40a8..0c24f6860 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -418,6 +418,9 @@ class DataSource extends Object{ } break; } + if(empty($val)){ + return false; + } $query = r($key, $this->value($val, $model->getColumnType($model->primaryKey)), $query); } } diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 6bd7cb3a1..24a0d1ed3 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -184,7 +184,7 @@ class DboSource extends DataSource { $all = true; $field = Inflector::underscore(preg_replace('/findAllBy/i', '', $args[0])); } - + $or = (strpos($field, '_or_') !== false); if ($or) { $field = explode('_or_', $field); @@ -212,7 +212,7 @@ class DboSource extends DataSource { } if ($all) { - + if (isset($params[3 + $off])) { $limit = $params[3 + $off]; } @@ -545,12 +545,12 @@ class DboSource extends DataSource { // Build final query SQL $query = $this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null); $resultSet = $this->fetchAll($query, $model->cacheQueries, $model->name); - + if ($resultSet === false) { $model->onError(); return false; } - + $filtered = $this->__filterResults($resultSet, $model); if ($model->recursive > 0) { @@ -666,14 +666,18 @@ class DboSource extends DataSource { $row =& $resultSet[$i]; $q = $this->insertQueryData($query, $resultSet[$i], $association, $assocData, $model, $linkModel, $stack); - $fetch = $this->fetchAll($q, $model->cacheQueries, $model->name); + if($q != false){ + $fetch = $this->fetchAll($q, $model->cacheQueries, $model->name); + } else { + $fetch = null; + } if (!empty($fetch) && is_array($fetch)) { - if ($recursive > 0) { - + if ($recursive > 0) { + foreach($linkModel->__associations as $type1) { foreach($linkModel->{$type1} as $assoc1 => $assocData1) { - + $deepModel =& $linkModel->{$assocData1['className']}; if ($deepModel->alias != $model->name) { $tmpStack = $stack;