Skip to content

Commit f3f230a

Browse files
authored
Merge pull request #1740 from jim5359/EmbedsMany-primaryKey-fix
EmbedsMany respect primaryKey on association
2 parents 069b233 + 4ae4a7c commit f3f230a

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)