mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Test for a self join only when needed.
This commit is contained in:
parent
a2f043d2a3
commit
b7527c6c3b
1 changed files with 8 additions and 9 deletions
|
@ -1599,18 +1599,17 @@ class DboSource extends DataSource {
|
|||
$this->getConstraint($type, $Model, $LinkModel, $association, array_merge($assocData, compact('external')))
|
||||
);
|
||||
|
||||
$selfJoin = ($Model->name === $LinkModel->name);
|
||||
|
||||
if ($external && !$selfJoin) {
|
||||
$modelAlias = $Model->alias;
|
||||
foreach ($conditions as $key => $condition) {
|
||||
if (is_numeric($key) && strpos($condition, $modelAlias . '.') !== false) {
|
||||
unset($conditions[$key]);
|
||||
if ($external) {
|
||||
// Self join
|
||||
if ($Model->name !== $LinkModel->name) {
|
||||
$modelAlias = $Model->alias;
|
||||
foreach ($conditions as $key => $condition) {
|
||||
if (is_numeric($key) && strpos($condition, $modelAlias . '.') !== false) {
|
||||
unset($conditions[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($external) {
|
||||
$query = array_merge($assocData, array(
|
||||
'conditions' => $conditions,
|
||||
'table' => $this->fullTableName($LinkModel),
|
||||
|
|
Loading…
Add table
Reference in a new issue