diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 368d81243..2730e6cf0 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -830,6 +830,7 @@ class DboSource extends DataSource { if (!isset($queryData['selfJoin'])) { $queryData['selfJoin'] = array(); + $self = array( 'fields' => $this->fields($model, null, $queryData['fields']), 'joins' => array(array( @@ -845,6 +846,12 @@ class DboSource extends DataSource { 'conditions'=> $queryData['conditions'], 'order' => $queryData['order'] ); + + if (!empty($queryData['joins'])) { + foreach($queryData['joins'] as $join) { + $self['joins'][] = $join; + } + } if($this->__bypass === false) { $self['fields'] = am($self['fields'], $this->fields($linkModel, $alias, '')); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 02e157a6b..005ffb37d 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -511,8 +511,8 @@ class DboSourceTest extends UnitTestCase { } } - $query = $this->db->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null); - $this->assertPattern('/^SELECT\s+(.+)FROM(.+)LEFT\s+JOIN\s+`category`\s+AS\s+`ParentCat`\s+ON\s+`Category2`\.`parent_id`\s+=\s+`ParentCat`\.`id`\s+WHERE/', $query); + $query = $this->db->generateAssociationQuery($this->model->Category2, $null, null, null, null, $queryData, false, $null); + $this->assertPattern('/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\s+WHERE/', $query); $this->model = new TestModel4(); $this->model->loadInfo();