From c9e0131d6a93901d9ce2806ab10b8cd38ea4d51a Mon Sep 17 00:00:00 2001 From: Ber Clausen Date: Tue, 5 Nov 2013 19:21:51 -0300 Subject: [PATCH] Only generate query data for hasOne and belongsTo associations. Avoid calling generateAssociationQuery(): * when the return value will never be usefull (True in this case) * to avoid polluting $queryData with uneeded fields Later, the SQL statement for the primary, and 'hasOne' plus 'belongsTo' relationships, is built. --- lib/Cake/Model/Datasource/DboSource.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index ee1712c54..29284e211 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1056,7 +1056,12 @@ class DboSource extends DataSource { unset($_associations[2], $_associations[3]); } + // Generate hasOne and belongsTo associations inside $queryData foreach ($_associations as $type) { + if ($type !== 'hasOne' && $type !== 'belongsTo') { + continue; + } + foreach ($model->{$type} as $assoc => $assocData) { $linkModel = $model->{$assoc}; $external = isset($assocData['external']); @@ -1073,6 +1078,7 @@ class DboSource extends DataSource { } } + // Build SQL statement with the primary model, plus hasOne and belongsTo associations $query = $this->generateAssociationQuery($model, null, null, null, null, $queryData, false, $null); $resultSet = $this->fetchAll($query, $model->cacheQueries); @@ -1084,6 +1090,7 @@ class DboSource extends DataSource { $filtered = array(); + // Filter hasOne and belongsTo associations if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { $filtered = $this->_filterResults($resultSet, $model); }