Skip to content

Commit d795dac

Browse files
authored
EmbedsMany respect primaryKey on association
1 parent bc78c75 commit d795dac

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
@@ -236,7 +236,7 @@ public function attach(Model $model)
236236
protected function associateNew($model)
237237
{
238238
// Create a new key if needed.
239-
if (!$model->getAttribute('_id')) {
239+
if ($model->getKeyName() == '_id' && !$model->getAttribute('_id')) {
240240
$model->setAttribute('_id', new ObjectID);
241241
}
242242

0 commit comments

Comments
 (0)