Browse Source

Fixed the rest of the failing test

Jose Lorenzo Rodriguez 11 years ago
parent
commit
cb89af6c6e
1 changed files with 16 additions and 13 deletions
  1. 16 13
      src/ORM/Marshaller.php

+ 16 - 13
src/ORM/Marshaller.php

@@ -348,17 +348,20 @@ class Marshaller {
 	public function mergeMany($entities, array $data, array $options = []) {
 		$primary = (array)$this->_table->primaryKey();
 
-		$data = new Collection($data);
-		$data = $data->groupBy(function ($el) use ($primary) {
-			$keys = [];
-			foreach ($primary as $key) {
-				$keys[] = isset($el[$key]) ? $el[$key] : '';
-			}
-			return implode(';', $keys);
-		});
-		$indexed = $data->toArray();
+		$indexed = (new Collection($data))
+			->groupBy(function ($el) use ($primary) {
+				$keys = [];
+				foreach ($primary as $key) {
+					$keys[] = isset($el[$key]) ? $el[$key] : '';
+				}
+				return implode(';', $keys);
+			})
+			->map(function ($element, $key) {
+				return $key === '' ? $element : $element[0];
+			})
+			->toArray();
 
-		$new = isset($indexed[null]) ? [$indexed[null]] : [];
+		$new = isset($indexed[null]) ? $indexed[null] : [];
 		unset($indexed[null]);
 		$output = [];
 
@@ -373,7 +376,7 @@ class Marshaller {
 				continue;
 			}
 
-			$output[] = $this->merge($entity, $indexed[$key][0], $options);
+			$output[] = $this->merge($entity, $indexed[$key], $options);
 			unset($indexed[$key]);
 		}
 
@@ -394,13 +397,13 @@ class Marshaller {
 		if ($maybeExistentQuery) {
 			foreach ($maybeExistentQuery as $entity) {
 				$key = implode(';', $entity->extract($primary));
-				$output[] = $this->merge($entity, $indexed[$key][0], $options);
+				$output[] = $this->merge($entity, $indexed[$key], $options);
 				unset($indexed[$key]);
 			}
 		}
 
 		foreach ((new Collection($indexed))->append($new) as $value) {
-			$output[] = $this->one($value[0], $options);
+			$output[] = $this->one($value, $options);
 		}
 
 		return $output;