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
This commit is contained in:
gwoo 2009-07-02 23:14:38 +00:00
parent a6d3193a6d
commit 92b8e87ed7
2 changed files with 27 additions and 12 deletions

View file

@ -627,16 +627,22 @@ class DboSource extends DataSource {
$queryData['fields'] = $this->fields($model);
}
foreach ($model->__associations as $type) {
foreach ($model->{$type} as $assoc => $assocData) {
if ($model->recursive > -1) {
$linkModel =& $model->{$assoc};
$external = isset($assocData['external']);
$_associations = $model->__associations;
if ($model->useDbConfig == $linkModel->useDbConfig) {
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) {
$linkedModels[] = $type . '/' . $assoc;
}
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) {
$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] = true;
}
}
}
@ -653,12 +659,12 @@ class DboSource extends DataSource {
$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 file

@ -12082,6 +12082,15 @@ class ModelTest extends CakeTestCase {
$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);