mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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
This commit is contained in:
parent
6afa21cb18
commit
d489d490a6
4 changed files with 10 additions and 11 deletions
|
@ -1297,7 +1297,7 @@ class DboSource extends DataSource {
|
||||||
$query = array_merge(array('order' => $assocData['order'], 'limit' => $assocData['limit']), $query);
|
$query = array_merge(array('order' => $assocData['order'], 'limit' => $assocData['limit']), $query);
|
||||||
} else {
|
} else {
|
||||||
$join = array(
|
$join = array(
|
||||||
'table' => $this->fullTableName($linkModel),
|
'table' => $linkModel,
|
||||||
'alias' => $alias,
|
'alias' => $alias,
|
||||||
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
|
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
|
||||||
'conditions' => trim($this->conditions($conditions, true, false, $model))
|
'conditions' => trim($this->conditions($conditions, true, false, $model))
|
||||||
|
@ -1336,7 +1336,7 @@ class DboSource extends DataSource {
|
||||||
$joinKeys = array($assocData['foreignKey'], $assocData['associationForeignKey']);
|
$joinKeys = array($assocData['foreignKey'], $assocData['associationForeignKey']);
|
||||||
list($with, $joinFields) = $model->joinModel($assocData['with'], $joinKeys);
|
list($with, $joinFields) = $model->joinModel($assocData['with'], $joinKeys);
|
||||||
|
|
||||||
$joinTbl = $this->fullTableName($model->{$with});
|
$joinTbl = $model->{$with};
|
||||||
$joinAlias = $joinTbl;
|
$joinAlias = $joinTbl;
|
||||||
|
|
||||||
if (is_array($joinFields) && !empty($joinFields)) {
|
if (is_array($joinFields) && !empty($joinFields)) {
|
||||||
|
@ -1346,8 +1346,8 @@ class DboSource extends DataSource {
|
||||||
$joinFields = array();
|
$joinFields = array();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$joinTbl = $this->fullTableName($assocData['joinTable']);
|
$joinTbl = $assocData['joinTable'];
|
||||||
$joinAlias = $joinTbl;
|
$joinAlias = $this->fullTableName($assocData['joinTable']);
|
||||||
}
|
}
|
||||||
$query = array(
|
$query = array(
|
||||||
'conditions' => $assocData['conditions'],
|
'conditions' => $assocData['conditions'],
|
||||||
|
@ -1436,6 +1436,9 @@ class DboSource extends DataSource {
|
||||||
if (!empty($data['conditions'])) {
|
if (!empty($data['conditions'])) {
|
||||||
$data['conditions'] = trim($this->conditions($data['conditions'], true, false));
|
$data['conditions'] = trim($this->conditions($data['conditions'], true, false));
|
||||||
}
|
}
|
||||||
|
if (!empty($data['table'])) {
|
||||||
|
$data['table'] = $this->fullTableName($data['table']);
|
||||||
|
}
|
||||||
return $this->renderJoinStatement($data);
|
return $this->renderJoinStatement($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1730,7 +1733,7 @@ class DboSource extends DataSource {
|
||||||
if (isset($model->{$assoc}) && $model->useDbConfig == $model->{$assoc}->useDbConfig) {
|
if (isset($model->{$assoc}) && $model->useDbConfig == $model->{$assoc}->useDbConfig) {
|
||||||
$assocData = $model->getAssociated($assoc);
|
$assocData = $model->getAssociated($assoc);
|
||||||
$join[] = $this->buildJoinStatement(array(
|
$join[] = $this->buildJoinStatement(array(
|
||||||
'table' => $this->fullTableName($model->{$assoc}),
|
'table' => $model->{$assoc},
|
||||||
'alias' => $assoc,
|
'alias' => $assoc,
|
||||||
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
|
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
|
||||||
'conditions' => trim($this->conditions(
|
'conditions' => trim($this->conditions(
|
||||||
|
|
|
@ -2132,11 +2132,6 @@ class Model extends Overloadable {
|
||||||
if (!$db =& ConnectionManager::getDataSource($this->useDbConfig)) {
|
if (!$db =& ConnectionManager::getDataSource($this->useDbConfig)) {
|
||||||
return false;
|
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);
|
$results = $db->read($this, $query);
|
||||||
$this->resetAssociations();
|
$this->resetAssociations();
|
||||||
|
|
||||||
|
|
|
@ -1461,6 +1461,7 @@ class DboSourceTest extends CakeTestCase {
|
||||||
'order' => array(),
|
'order' => array(),
|
||||||
'group' => null
|
'group' => null
|
||||||
);
|
);
|
||||||
|
$queryData['joins'][0]['table'] = $this->testDb->fullTableName($queryData['joins'][0]['table']);
|
||||||
$this->assertEqual($queryData, $expected);
|
$this->assertEqual($queryData, $expected);
|
||||||
|
|
||||||
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
$result = $this->testDb->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||||
|
|
|
@ -5158,7 +5158,7 @@ class ModelReadTest extends BaseModelTest {
|
||||||
'group' => null,
|
'group' => null,
|
||||||
'joins' => array(array(
|
'joins' => array(array(
|
||||||
'alias' => 'ArticlesTag',
|
'alias' => 'ArticlesTag',
|
||||||
'table' => $this->db->fullTableName('articles_tags'),
|
'table' => 'articles_tags',
|
||||||
'conditions' => array(
|
'conditions' => array(
|
||||||
array("ArticlesTag.article_id" => '{$__cakeID__$}'),
|
array("ArticlesTag.article_id" => '{$__cakeID__$}'),
|
||||||
array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id'))
|
array("ArticlesTag.tag_id" => $this->db->identifier('Tag.id'))
|
||||||
|
|
Loading…
Reference in a new issue