Permalink
Browse files

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
  • Loading branch information...
1 parent ba249ae commit 2097d5a968e57ea72bbe1710b667e20130374402 @markstory markstory committed Feb 18, 2012
Showing with 9 additions and 7 deletions.
  1. +9 −7 lib/Cake/Model/Datasource/DboSource.php
@@ -1389,14 +1389,16 @@ protected function _mergeAssociation(&$data, &$merge, $association, $type, $self
}
} 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;
}
}
}

0 comments on commit 2097d5a

Please sign in to comment.