Skip to content

Commit

Permalink
Call getDataSource() instead of the directly calling
Browse files Browse the repository at this point in the history
ConnectionManager::getDataSource().
  • Loading branch information
bar committed Nov 12, 2013
1 parent c1f3d9c commit 52d4257
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -1117,20 +1117,16 @@ public function read(Model $Model, $queryData = array(), $recursive = null) {
$LinkModel = $Model->{$assoc}; $LinkModel = $Model->{$assoc};


if (!isset($linkedModels[$type . '/' . $assoc])) { if (!isset($linkedModels[$type . '/' . $assoc])) {
if ($Model->useDbConfig === $LinkModel->useDbConfig) { $db = $Model->useDbConfig === $LinkModel->useDbConfig ? $this : $LinkModel->getDataSource();
$db = $this;
} else {
$db = ConnectionManager::getDataSource($LinkModel->useDbConfig);
}
} elseif ($Model->recursive > 1) { } elseif ($Model->recursive > 1) {
$db = $this; $db = $this;
} }


if (isset($db) && method_exists($db, 'queryAssociation')) { if (isset($db) && method_exists($db, 'queryAssociation')) {
$stack = array($assoc); $stack = array($assoc);
$stack['_joined'] = $joined; $stack['_joined'] = $joined;

$db->queryAssociation($Model, $LinkModel, $type, $assoc, $assocData, $array, true, $resultSet, $Model->recursive - 1, $stack); $db->queryAssociation($Model, $LinkModel, $type, $assoc, $assocData, $array, true, $resultSet, $Model->recursive - 1, $stack);
unset($db);


if ($type === 'hasMany' || $type === 'hasAndBelongsToMany') { if ($type === 'hasMany' || $type === 'hasAndBelongsToMany') {
$filtered[] = $assoc; $filtered[] = $assoc;
Expand Down Expand Up @@ -1246,11 +1242,7 @@ public function queryAssociation(Model $Model, &$LinkModel, $type, $association,
$tmpStack = $stack; $tmpStack = $stack;
$tmpStack[] = $assoc1; $tmpStack[] = $assoc1;


if ($LinkModel->useDbConfig === $DeepModel->useDbConfig) { $db = $LinkModel->useDbConfig === $DeepModel->useDbConfig ? $this : $DeepModel->getDataSource();
$db = $this;
} else {
$db = ConnectionManager::getDataSource($DeepModel->useDbConfig);
}


$db->queryAssociation($LinkModel, $DeepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack); $db->queryAssociation($LinkModel, $DeepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
} }
Expand Down Expand Up @@ -1331,11 +1323,9 @@ public function queryAssociation(Model $Model, &$LinkModel, $type, $association,
if ($type1 === 'belongsTo' || ($DeepModel->alias === $modelAlias && $type === 'belongsTo') || ($DeepModel->alias !== $modelAlias)) { if ($type1 === 'belongsTo' || ($DeepModel->alias === $modelAlias && $type === 'belongsTo') || ($DeepModel->alias !== $modelAlias)) {
$tmpStack = $stack; $tmpStack = $stack;
$tmpStack[] = $assoc1; $tmpStack[] = $assoc1;
if ($LinkModel->useDbConfig == $DeepModel->useDbConfig) {
$db = $this; $db = $LinkModel->useDbConfig === $DeepModel->useDbConfig ? $this : $DeepModel->getDataSource();
} else {
$db = ConnectionManager::getDataSource($DeepModel->useDbConfig);
}
$db->queryAssociation($LinkModel, $DeepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack); $db->queryAssociation($LinkModel, $DeepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
} }
} }
Expand Down

0 comments on commit 52d4257

Please sign in to comment.