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

Conflicts:

	cake/libs/model/datasources/dbo_source.php
  • Loading branch information...
commit 9558943b3743951ee6cbfff36c7ff8cf3cdf37d0 1 parent 52f4b08
Mark Story markstory authored
Showing with 10 additions and 8 deletions.
  1. +10 −8 cake/libs/model/datasources/dbo_source.php
18 cake/libs/model/datasources/dbo_source.php
View
@@ -1192,14 +1192,16 @@ function __mergeAssociation(&$data, $merge, $association, $type, $selfJoin = fal
}
} else {
foreach ($merge as $i => $row) {
- if (count($row) == 1) {
- if (empty($data[$association]) || (isset($data[$association]) && !in_array($row[$association], $data[$association]))) {
- $data[$association][] = $row[$association];
- }
- } else if (!empty($row)) {
- $tmp = array_merge($row[$association], $row);
- unset($tmp[$association]);
- $data[$association][] = $tmp;
+ $insert = array();
+ if (count($row) === 1) {
+ $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.