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 60df31cfb6
commit 89b9bb7297

View file

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