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 { } else {
foreach ($merge as $i => $row) { foreach ($merge as $i => $row) {
$insert = array();
if (count($row) === 1) { if (count($row) === 1) {
if (empty($data[$association]) || (isset($data[$association]) && !in_array($row[$association], $data[$association]))) { $insert = $row[$association];
$data[$association][] = $row[$association]; } elseif (isset($row[$association])) {
} $insert = array_merge($row[$association], $row);
} elseif (!empty($row)) { unset($insert[$association]);
$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;
} }
} }
} }