Skip to content

Commit

Permalink
Merge pull request mongodb#1740 from jim5359/EmbedsMany-primaryKey-fix
Browse files Browse the repository at this point in the history
EmbedsMany respect primaryKey on association
  • Loading branch information
mnphpexpert committed Sep 12, 2019
2 parents 9ed3528 + c074e2b commit 22996c2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Relations/EmbedsMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,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);
}

Expand Down

0 comments on commit 22996c2

Please sign in to comment.