From cc46c03f31d95fc8bd828a7220d54392f292379f Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 4 Apr 2007 21:40:59 +0000 Subject: [PATCH] Adding fixes for association conditions git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4763 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 8 ++++---- .../cases/libs/model/datasources/dbo_source.test.php | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 6a27d6cde..7197f5d4a 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -994,16 +994,16 @@ class DboSource extends DataSource { } } else { if ($type == 'hasOne') { - $conditions = array("{$alias}.{$assocData['foreignKey']}" => '{$__cakeIdentifier[' . "{$model->name}.{$model->primaryKey}" . ']__$}'); + $conditions = $this->__mergeConditions($queryData['conditions'], array("{$alias}.{$assocData['foreignKey']}" => '{$__cakeIdentifier[' . "{$model->name}.{$model->primaryKey}" . ']__$}')); } elseif ($type == 'belongsTo') { - $conditions = array($model->escapeField($assocData['foreignKey']) => '{$__cakeIdentifier[' . "{$alias}.{$linkModel->primaryKey}" . ']__$}'); + $conditions = $this->__mergeConditions($assocData['conditions'], array($model->escapeField($assocData['foreignKey']) => '{$__cakeIdentifier[' . "{$alias}.{$linkModel->primaryKey}" . ']__$}')); } $join = array( 'table' => $this->fullTableName($linkModel), 'alias' => $alias, 'type' => 'LEFT', - 'conditions' => $conditions + 'conditions' => preg_replace('/^\s*WHERE\s*/', '', trim($this->conditions($conditions))) ); $queryData['fields'] = am($queryData['fields'], $fields); @@ -1105,7 +1105,7 @@ class DboSource extends DataSource { function renderJoinStatement($data) { extract($data); - return trim("{$type} JOIN {$table} {$alias} ON {$conditions}"); + return trim("{$type} JOIN {$table} {$alias} ON ({$conditions})"); } function renderStatement($data) { 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 40b18dcd4..1d4baec1c 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -662,6 +662,7 @@ class DboSourceTest extends UnitTestCase { '\s+ON\s+`Featured2`\.`article_featured2_id` = `ArticleFeatured2`\.`id`' . '\s+AND\s+`ArticleFeatured2`\.`published` = \'Y\'\s+' . '\s+WHERE\s+1\s+=\s+1\s*$/', $result); + debug($result); } function testGenerateAssociationQueryHasOne() {