Permalink
Browse files

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.
  • Loading branch information...
1 parent 2532228 commit c9e0131d6a93901d9ce2806ab10b8cd38ea4d51a @bar bar committed Nov 5, 2013
Showing with 7 additions and 0 deletions.
  1. +7 −0 lib/Cake/Model/Datasource/DboSource.php
@@ -1056,7 +1056,12 @@ public function read(Model $model, $queryData = array(), $recursive = null) {
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 @@ public function read(Model $model, $queryData = array(), $recursive = null) {
}
}
+ // 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 @@ public function read(Model $model, $queryData = array(), $recursive = null) {
$filtered = array();
+ // Filter hasOne and belongsTo associations
if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') {
$filtered = $this->_filterResults($resultSet, $model);
}

0 comments on commit c9e0131

Please sign in to comment.