diff --git a/src/ChangesCollector.php b/src/ChangesCollector.php index e615b57..2d8e423 100644 --- a/src/ChangesCollector.php +++ b/src/ChangesCollector.php @@ -25,6 +25,8 @@ public function changes($object) return Converter::convertJsonPatchToMongoUpdate($diff); } + unset($values['_id']); + return ['$set' => $values]; })->call($object); } diff --git a/src/Hydrator.php b/src/Hydrator.php index 8014c62..71275bf 100644 --- a/src/Hydrator.php +++ b/src/Hydrator.php @@ -1,6 +1,7 @@ prototypeModel) { - $this->prototypeModel = new $this->modelClass(); - - $this->hydrate([], $this->prototypeModel); - } - - return clone $this->prototypeModel; + return $this->hydrate($values, build_object($this->modelClass, $values)); } /** @@ -46,7 +38,7 @@ public function create() */ public function hydrate(array $values, $model = null) { - $model = $model ?: $this->create(); + $model = $model ?: $this->create($values); if (isset($values['_id'])) { $values['_id'] = (string) $values['_id'];