Skip to content
This repository
Browse code

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 authored February 17, 2012
18  cake/libs/model/datasources/dbo_source.php
@@ -1192,14 +1192,16 @@ function __mergeAssociation(&$data, $merge, $association, $type, $selfJoin = fal
1192 1192
 				}
1193 1193
 			} else {
1194 1194
 				foreach ($merge as $i => $row) {
1195  
-					if (count($row) == 1) {
1196  
-						if (empty($data[$association]) || (isset($data[$association]) && !in_array($row[$association], $data[$association]))) {
1197  
-							$data[$association][] = $row[$association];
1198  
-						}
1199  
-					} else if (!empty($row)) {
1200  
-						$tmp = array_merge($row[$association], $row);
1201  
-						unset($tmp[$association]);
1202  
-						$data[$association][] = $tmp;
  1195
+					$insert = array();
  1196
+					if (count($row) === 1) {
  1197
+						$insert = $row[$association];
  1198
+					} elseif (isset($row[$association])) {
  1199
+						$insert = array_merge($row[$association], $row);
  1200
+						unset($insert[$association]);
  1201
+					}
  1202
+
  1203
+					if (empty($data[$association]) || (isset($data[$association]) && !in_array($insert, $data[$association], true))) {
  1204
+						$data[$association][] = $insert;
1203 1205
 					}
1204 1206
 				}
1205 1207
 			}

0 notes on commit 9558943

Please sign in to comment.
Something went wrong with that request. Please try again.