Skip to content

Commit eb1bd96

Browse files
committed
feat: unset default BelongsToMany relations when not loaded
1 parent 912b116 commit eb1bd96

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

packages/database/src/Mappers/SelectModelMapper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function map(mixed $from, mixed $to): array
5050
foreach ($model->getRelations() as $relation) {
5151
// When a nullable BelongsTo relation wasn't loaded, we need to make sure to unset it if it has a default value.
5252
// If we wouldn't do this, the default value would overwrite the "unloaded" value on the next time saving the model
53-
if (! $relation instanceof BelongsTo) {
54-
continue;
55-
}
56-
57-
if (! $relation->property->isNullable()) {
53+
if ($relation instanceof BelongsTo) {
54+
if (! $relation->property->isNullable()) {
55+
continue;
56+
}
57+
} elseif (! $relation instanceof BelongsToMany) {
5858
continue;
5959
}
6060

0 commit comments

Comments
 (0)