mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix duplicate items in HABTM associations.
Apply patch from 'Kim Biesbjerg'. Fixes issues where nested HABTM associations would create duplicate content. Fixes #2564 Fixes #1598
This commit is contained in:
parent
ba249aeff6
commit
2097d5a968
1 changed files with 9 additions and 7 deletions
|
@ -1389,14 +1389,16 @@ class DboSource extends DataSource {
|
|||
}
|
||||
} else {
|
||||
foreach ($merge as $i => $row) {
|
||||
$insert = array();
|
||||
if (count($row) === 1) {
|
||||
if (empty($data[$association]) || (isset($data[$association]) && !in_array($row[$association], $data[$association]))) {
|
||||
$data[$association][] = $row[$association];
|
||||
$insert = $row[$association];
|
||||
} elseif (isset($row[$association])) {
|
||||
$insert = array_merge($row[$association], $row);
|
||||
unset($insert[$association]);
|
||||
}
|
||||
} elseif (!empty($row)) {
|
||||
$tmp = array_merge($row[$association], $row);
|
||||
unset($tmp[$association]);
|
||||
$data[$association][] = $tmp;
|
||||
|
||||
if (empty($data[$association]) || (isset($data[$association]) && !in_array($insert, $data[$association], true))) {
|
||||
$data[$association][] = $insert;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue