From 9e3816b362c4168888ebefd26bb085a7bb92730a Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Mon, 5 Nov 2018 18:08:28 -0800 Subject: [PATCH 1/2] EmbedsMany respect primaryKey on association --- src/Jenssegers/Mongodb/Relations/EmbedsMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php index b0e40893d..d16a8ca15 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php @@ -236,7 +236,7 @@ public function attach(Model $model) protected function associateNew($model) { // Create a new key if needed. - if (!$model->getAttribute('_id')) { + if ($model->getKeyName() == '_id' && !$model->getAttribute('_id')) { $model->setAttribute('_id', new ObjectID); } From c074e2b88023858bcbb3802db15e522ab2017db7 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Wed, 11 Sep 2019 11:30:35 -0700 Subject: [PATCH 2/2] Update src/Jenssegers/Mongodb/Relations/EmbedsMany.php Co-Authored-By: Jens Segers --- src/Jenssegers/Mongodb/Relations/EmbedsMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php index 3c720b73d..85574eeb0 100644 --- a/src/Jenssegers/Mongodb/Relations/EmbedsMany.php +++ b/src/Jenssegers/Mongodb/Relations/EmbedsMany.php @@ -237,7 +237,7 @@ public function attach(Model $model) protected function associateNew($model) { // Create a new key if needed. - if ($model->getKeyName() == '_id' && !$model->getAttribute('_id')) { + if ($model->getKeyName() === '_id' && !$model->getAttribute('_id')) { $model->setAttribute('_id', new ObjectID); }