Skip to content

Commit

Permalink
feat: generate new objectId only if _id attribute exists
Browse files Browse the repository at this point in the history
  • Loading branch information
radu-c-tag committed Aug 27, 2024
1 parent 72a45f1 commit 8a107c2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Relations/EmbedsMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ public function attach(Model $model)
protected function associateNew($model)
{
// Create a new key if needed.
if (!$model->getKey()) {
$model->setAttribute($model->getKeyName(), new ObjectID());
if ($model->getKeyName() === '_id' && !$model->getAttribute('_id')) {
$model->setAttribute('_id', new ObjectID);
}

$records = $this->getEmbedded();
Expand Down

0 comments on commit 8a107c2

Please sign in to comment.