From c2dcc109963bd03eab99eff48f9aa062627268b8 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sat, 4 Feb 2006 07:33:20 +0000 Subject: [PATCH] Merging fixes and enhancements into trunk Revision: [1925] Adding fix for association conditions when set in the association array Revision: [1924] Adding fixes for $recursive Revision: [1923] Adding fix from Ticket #362 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1926 3807eeeb-6ff5-0310-8944-8be069107fe0 --- VERSION.txt | 2 +- cake/libs/model/datasources/dbo_source.php | 36 ++++++++++++++++++++-- cake/libs/model/dbo/dbo_mysql.php | 4 +-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 940160cd4..ddd704bc5 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -0.10.8.1922 RC 4 \ No newline at end of file +0.10.8.1926 RC 4 \ No newline at end of file diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index d9150f491..36b2ddd1a 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -370,6 +370,7 @@ class DboSource extends DataSource $this->__assocJoins = null; if(!is_null($recursive)) { + $_recursive = $model->recursive; $model->recursive = $recursive; } @@ -435,7 +436,7 @@ class DboSource extends DataSource foreach ($resultSet[$i][$linkModel->name] as $value) { $datas[][$linkModel->name] = $value[$linkModel->primaryKey]; - $fetch = $this->queryDeepAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $array, false, $datas); + $fetch = $this->queryDeepAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $array, true, $datas); unset($datas); if (!empty($fetch[0])) @@ -474,6 +475,11 @@ class DboSource extends DataSource } } } + + if(!is_null($recursive)) + { + $model->recursive = $_recursive; + } return $resultSet; } @@ -506,8 +512,6 @@ class DboSource extends DataSource */ function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet) { - //$external = (($linkModel->db === $this) && $resultSet == null); - $query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet); if ($query) { @@ -695,6 +699,19 @@ class DboSource extends DataSource $sql .= ' AS '.$this->name($alias).' ON '.$this->name($alias).'.'; $sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey); $sql .= $this->order($assocData['order']); + + if (isset($assocData['conditions'])) + { + if(is_array($queryData['conditions'])) + { + $queryData['conditions'] = array_merge($assocData['conditions'], $queryData['conditions']); + } + else + { + $queryData['conditions'] = $assocData['conditions']; + } + } + if (!in_array($sql, $queryData['joins'])) { $queryData['joins'][] = $sql; @@ -745,6 +762,19 @@ class DboSource extends DataSource $sql .= ' AS ' . $this->name($alias) . ' ON '; $sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']); $sql .= '='.$this->name($alias).'.'.$this->name($linkModel->primaryKey); + + if (isset($assocData['conditions'])) + { + if(is_array($queryData['conditions'])) + { + $queryData['conditions'] = array_merge($assocData['conditions'], $queryData['conditions']); + } + else + { + $queryData['conditions'] = $assocData['conditions']; + } + } + if (!in_array($sql, $queryData['joins'])) { $queryData['joins'][] = $sql; diff --git a/cake/libs/model/dbo/dbo_mysql.php b/cake/libs/model/dbo/dbo_mysql.php index 0d227ee85..f7c0a6794 100644 --- a/cake/libs/model/dbo/dbo_mysql.php +++ b/cake/libs/model/dbo/dbo_mysql.php @@ -156,13 +156,13 @@ class DboMysql extends DboSource elseif (count($args) > 1 && strpos($args[0], 'findBy') === 0) { $field = Inflector::underscore(str_replace('findBy', '', $args[0])); - $query = '`' . $args[2]->name . '.' . $field . '` = ' . $this->value($args[1][0]); + $query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]); return $args[2]->find($query); } elseif (count($args) > 1 && strpos($args[0], 'findAllBy') === 0) { $field = Inflector::underscore(str_replace('findAllBy', '', $args[0])); - $query = '`' . $args[2]->name . '.' . $field . '` = ' . $this->value($args[1][0]); + $query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]); return $args[2]->findAll($query); } }