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
60df31cfb6
commit
89b9bb7297
1 changed files with 9 additions and 7 deletions
|
@ -1406,14 +1406,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];
|
||||
}
|
||||
} elseif (!empty($row)) {
|
||||
$tmp = array_merge($row[$association], $row);
|
||||
unset($tmp[$association]);
|
||||
$data[$association][] = $tmp;
|
||||
$insert = $row[$association];
|
||||
} elseif (isset($row[$association])) {
|
||||
$insert = array_merge($row[$association], $row);
|
||||
unset($insert[$association]);
|
||||
}
|
||||
|
||||
if (empty($data[$association]) || (isset($data[$association]) && !in_array($insert, $data[$association], true))) {
|
||||
$data[$association][] = $insert;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue