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:
mark_story 2012-02-17 21:09:48 -05:00
parent ba249aeff6
commit 2097d5a968

View file

@ -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;
}
}
}