Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving 'joins' key conversion into DboSource::buildJoinStatement()

Having this in Model felt like the wrong layer for it to reside.
This also simplifies a few things internally.
Refs #1517
  • Loading branch information...
commit d489d490a6e688d09191ec1ca5dbc79a7f729d2b 1 parent 6afa21c
@markstory markstory authored
View
13 cake/libs/model/datasources/dbo_source.php
@@ -1297,7 +1297,7 @@ function generateAssociationQuery(&$model, &$linkModel, $type, $association = nu
$query = array_merge(array('order' => $assocData['order'], 'limit' => $assocData['limit']), $query);
} else {
$join = array(
- 'table' => $this->fullTableName($linkModel),
+ 'table' => $linkModel,
'alias' => $alias,
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
'conditions' => trim($this->conditions($conditions, true, false, $model))
@@ -1336,7 +1336,7 @@ function generateAssociationQuery(&$model, &$linkModel, $type, $association = nu
$joinKeys = array($assocData['foreignKey'], $assocData['associationForeignKey']);
list($with, $joinFields) = $model->joinModel($assocData['with'], $joinKeys);
- $joinTbl = $this->fullTableName($model->{$with});
+ $joinTbl = $model->{$with};
$joinAlias = $joinTbl;
if (is_array($joinFields) && !empty($joinFields)) {
@@ -1346,8 +1346,8 @@ function generateAssociationQuery(&$model, &$linkModel, $type, $association = nu
$joinFields = array();
}
} else {
- $joinTbl = $this->fullTableName($assocData['joinTable']);
- $joinAlias = $joinTbl;
+ $joinTbl = $assocData['joinTable'];
+ $joinAlias = $this->fullTableName($assocData['joinTable']);
}
$query = array(
'conditions' => $assocData['conditions'],
@@ -1436,6 +1436,9 @@ function buildJoinStatement($join) {
if (!empty($data['conditions'])) {
$data['conditions'] = trim($this->conditions($data['conditions'], true, false));
}
+ if (!empty($data['table'])) {
+ $data['table'] = $this->fullTableName($data['table']);
+ }
return $this->renderJoinStatement($data);
}
@@ -1730,7 +1733,7 @@ function _getJoins($model) {
if (isset($model->{$assoc}) && $model->useDbConfig == $model->{$assoc}->useDbConfig) {
$assocData = $model->getAssociated($assoc);
$join[] = $this->buildJoinStatement(array(
- 'table' => $this->fullTableName($model->{$assoc}),
+ 'table' => $model->{$assoc},
'alias' => $assoc,
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
'conditions' => trim($this->conditions(
View
5 cake/libs/model/model.php
@@ -2132,11 +2132,6 @@ function find($conditions = null, $fields = array(), $order = null, $recursive =
if (!$db =& ConnectionManager::getDataSource($this->useDbConfig)) {
return false;
}
- if (!empty($query['joins']) && is_array($query['joins'])) {
- foreach($query['joins'] as $i => $join) {
- $query['joins'][$i]['table'] = $db->fullTableName($join['table']);
- }
- }
$results = $db->read($this, $query);
$this->resetAssociations();
View
1  cake/tests/cases/libs/model/datasources/dbo_source.test.php
@@ -1461,6 +1461,7 @@ function testGenerateAssociationQuerySelfJoin() {
'order' => array(),
'group' => null
);
+ $queryData['joins'][0]['table'] = $this->testDb->fullTableName($queryData['joins'][0]['table']);
$this->assertEqual($queryData, $expected);
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
View
2  cake/tests/cases/libs/model/model_read.test.php
@@ -5158,7 +5158,7 @@ function testHabtmFinderQuery() {
'group' => null,
'joins' => array(array(
'alias' => 'ArticlesTag',
- 'table' => $this->db->fullTableName('articles_tags'),
+ 'table' => 'articles_tags',
'conditions' => array(
array("ArticlesTag.article_id" => '{$__cakeID__$}'),
array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id'))
Please sign in to comment.
Something went wrong with that request. Please try again.