Skip to content

Commit 22996c2

Browse files
committed
Merge pull request mongodb#1740 from jim5359/EmbedsMany-primaryKey-fix
EmbedsMany respect primaryKey on association
2 parents 9ed3528 + c074e2b commit 22996c2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Jenssegers/Mongodb/Relations/EmbedsMany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function attach(Model $model)
227227
protected function associateNew($model)
228228
{
229229
// Create a new key if needed.
230-
if (!$model->getAttribute('_id')) {
230+
if ($model->getKeyName() === '_id' && !$model->getAttribute('_id')) {
231231
$model->setAttribute('_id', new ObjectID);
232232
}
233233

0 commit comments

Comments
 (0)