From dbbe90c22c09d4d4c846213ec420453001e26488 Mon Sep 17 00:00:00 2001 From: nate Date: Tue, 27 Mar 2007 01:59:39 +0000 Subject: [PATCH] Fixing issue in DboSource with left joins on self joins git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4687 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 7 +++++++ .../tests/cases/libs/model/datasources/dbo_source.test.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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();