Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 89b9bb72972365a817530ad68fbf60be9765acd8 1 parent 60df31c
@markstory markstory authored
Showing with 9 additions and 7 deletions.
  1. +9 −7 lib/Cake/Model/Datasource/DboSource.php
View
16 lib/Cake/Model/Datasource/DboSource.php
@@ -1406,14 +1406,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;
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.