Permalink
Browse files

Get Model associations only when needed.

  • Loading branch information...
1 parent 8355d32 commit 60a8f0900b8286c0c8b821788ab445aa8507574e @bar bar committed Dec 21, 2013
Showing with 14 additions and 9 deletions.
  1. +14 −9 lib/Cake/Model/Datasource/DboSource.php
@@ -1042,7 +1042,7 @@ public function read(Model $Model, $queryData = array(), $recursive = null) {
}
if ($recursive !== null) {
- $_recursive = $Model->recursive;
+ $modelRecursive = $Model->recursive;
$Model->recursive = $recursive;
}
@@ -1054,17 +1054,22 @@ public function read(Model $Model, $queryData = array(), $recursive = null) {
$queryData['fields'] = $this->fields($Model);
}
- $_associations = $Model->associations();
+ if ($Model->recursive === -1) {
+ // Primary model data only, no joins.
+ $associations = array();
- if ($Model->recursive == -1) {
- $_associations = array();
- } elseif ($Model->recursive === 0) {
- unset($_associations[2], $_associations[3]);
+ } else {
+ $associations = $Model->associations();
+
+ if ($Model->recursive === 0) {
+ // Primary model data and its domain.
+ unset($associations[2], $associations[3]);
+ }
}
// Generate hasOne and belongsTo associations inside $queryData
$linkedModels = array();
- foreach ($_associations as $type) {
+ foreach ($associations as $type) {
if ($type !== 'hasOne' && $type !== 'belongsTo') {
continue;
}
@@ -1113,7 +1118,7 @@ public function read(Model $Model, $queryData = array(), $recursive = null) {
$joined[$Model->alias] = (array)Hash::extract($queryData['joins'], '{n}.alias');
}
- foreach ($_associations as $type) {
+ foreach ($associations as $type) {
foreach ($Model->{$type} as $assoc => $assocData) {
$LinkModel = $Model->{$assoc};
@@ -1142,7 +1147,7 @@ public function read(Model $Model, $queryData = array(), $recursive = null) {
}
if ($recursive !== null) {
- $Model->recursive = $_recursive;
+ $Model->recursive = $modelRecursive;
}
return $resultSet;

0 comments on commit 60a8f09

Please sign in to comment.