mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding fixes for association conditions
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4763 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
06d6bbdbae
commit
cc46c03f31
2 changed files with 5 additions and 4 deletions
|
@ -994,16 +994,16 @@ class DboSource extends DataSource {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($type == 'hasOne') {
|
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') {
|
} 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(
|
$join = array(
|
||||||
'table' => $this->fullTableName($linkModel),
|
'table' => $this->fullTableName($linkModel),
|
||||||
'alias' => $alias,
|
'alias' => $alias,
|
||||||
'type' => 'LEFT',
|
'type' => 'LEFT',
|
||||||
'conditions' => $conditions
|
'conditions' => preg_replace('/^\s*WHERE\s*/', '', trim($this->conditions($conditions)))
|
||||||
);
|
);
|
||||||
$queryData['fields'] = am($queryData['fields'], $fields);
|
$queryData['fields'] = am($queryData['fields'], $fields);
|
||||||
|
|
||||||
|
@ -1105,7 +1105,7 @@ class DboSource extends DataSource {
|
||||||
|
|
||||||
function renderJoinStatement($data) {
|
function renderJoinStatement($data) {
|
||||||
extract($data);
|
extract($data);
|
||||||
return trim("{$type} JOIN {$table} {$alias} ON {$conditions}");
|
return trim("{$type} JOIN {$table} {$alias} ON ({$conditions})");
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderStatement($data) {
|
function renderStatement($data) {
|
||||||
|
|
|
@ -662,6 +662,7 @@ class DboSourceTest extends UnitTestCase {
|
||||||
'\s+ON\s+`Featured2`\.`article_featured2_id` = `ArticleFeatured2`\.`id`' .
|
'\s+ON\s+`Featured2`\.`article_featured2_id` = `ArticleFeatured2`\.`id`' .
|
||||||
'\s+AND\s+`ArticleFeatured2`\.`published` = \'Y\'\s+' .
|
'\s+AND\s+`ArticleFeatured2`\.`published` = \'Y\'\s+' .
|
||||||
'\s+WHERE\s+1\s+=\s+1\s*$/', $result);
|
'\s+WHERE\s+1\s+=\s+1\s*$/', $result);
|
||||||
|
debug($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testGenerateAssociationQueryHasOne() {
|
function testGenerateAssociationQueryHasOne() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue