Skip to content

Commit 8a107c2

Browse files
committed
feat: generate new objectId only if _id attribute exists
1 parent 72a45f1 commit 8a107c2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Relations/EmbedsMany.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public function attach(Model $model)
230230
protected function associateNew($model)
231231
{
232232
// Create a new key if needed.
233-
if (!$model->getKey()) {
234-
$model->setAttribute($model->getKeyName(), new ObjectID());
233+
if ($model->getKeyName() === '_id' && !$model->getAttribute('_id')) {
234+
$model->setAttribute('_id', new ObjectID);
235235
}
236236

237237
$records = $this->getEmbedded();

0 commit comments

Comments
 (0)