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.
This commit is contained in:
Ber Clausen 2013-11-05 19:21:51 -03:00
parent 2532228844
commit c9e0131d6a

View file

@ -1056,7 +1056,12 @@ class DboSource extends DataSource {
unset($_associations[2], $_associations[3]); unset($_associations[2], $_associations[3]);
} }
// Generate hasOne and belongsTo associations inside $queryData
foreach ($_associations as $type) { foreach ($_associations as $type) {
if ($type !== 'hasOne' && $type !== 'belongsTo') {
continue;
}
foreach ($model->{$type} as $assoc => $assocData) { foreach ($model->{$type} as $assoc => $assocData) {
$linkModel = $model->{$assoc}; $linkModel = $model->{$assoc};
$external = isset($assocData['external']); $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); $query = $this->generateAssociationQuery($model, null, null, null, null, $queryData, false, $null);
$resultSet = $this->fetchAll($query, $model->cacheQueries); $resultSet = $this->fetchAll($query, $model->cacheQueries);
@ -1084,6 +1090,7 @@ class DboSource extends DataSource {
$filtered = array(); $filtered = array();
// Filter hasOne and belongsTo associations
if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') { if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') {
$filtered = $this->_filterResults($resultSet, $model); $filtered = $this->_filterResults($resultSet, $model);
} }