Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for cross database joins when recursive < 1

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8212 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 92b8e87ed720a0b37d2c98c0cfe35ca0ecc2a752 1 parent a6d3193
gwoo authored
View
28 cake/libs/model/datasources/dbo_source.php
@@ -627,16 +627,22 @@ function read(&$model, $queryData = array(), $recursive = null) {
$queryData['fields'] = $this->fields($model);
}
- foreach ($model->__associations as $type) {
+ $_associations = $model->__associations;
+
+ if ($model->recursive == -1) {
+ $_associations = array();
+ } else if ($model->recursive == 0) {
+ unset($_associations[2], $_associations[3]);
+ }
+
+ foreach ($_associations as $type) {
foreach ($model->{$type} as $assoc => $assocData) {
- if ($model->recursive > -1) {
- $linkModel =& $model->{$assoc};
- $external = isset($assocData['external']);
+ $linkModel =& $model->{$assoc};
+ $external = isset($assocData['external']);
- if ($model->useDbConfig == $linkModel->useDbConfig) {
- if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) {
- $linkedModels[] = $type . '/' . $assoc;
- }
+ if ($model->useDbConfig == $linkModel->useDbConfig) {
+ if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) {
+ $linkedModels[$type . '/' . $assoc] = true;
}
}
}
@@ -653,12 +659,12 @@ function read(&$model, $queryData = array(), $recursive = null) {
$filtered = $this->__filterResults($resultSet, $model);
- if ($model->recursive > 0) {
- foreach ($model->__associations as $type) {
+ if ($model->recursive > -1) {
+ foreach ($_associations as $type) {
foreach ($model->{$type} as $assoc => $assocData) {
$linkModel =& $model->{$assoc};
- if (!in_array($type . '/' . $assoc, $linkedModels)) {
+ if (empty($linkedModels[$type . '/' . $assoc])) {
if ($model->useDbConfig == $linkModel->useDbConfig) {
$db =& $this;
} else {
View
9 cake/tests/cases/libs/model/model.test.php
@@ -12082,6 +12082,15 @@ function testCrossDatabaseJoins() {
$TestModel->User->setDataSource('test2');
$TestModel->Comment->setDataSource('test2');
+ foreach ($expected as $key => $value) {
+ unset($value['Comment'], $value['Tag']);
+ $expected[$key] = $value;
+ }
+
+ $TestModel->recursive = 0;
+ $result = $TestModel->find('all');
+ $this->assertEqual($result, $expected);
+
$result = Set::extract($TestModel->User->find('all'), '{n}.User.id');
$this->assertEqual($result, array('1', '2', '3', '4'));
$this->assertEqual($TestModel->find('all'), $expected);
Please sign in to comment.
Something went wrong with that request. Please try again.