Skip to content

Commit e2b3028

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

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/database/src/Mappers/SelectModelMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public function map(mixed $from, mixed $to): array
4848

4949
foreach ($objects as $i => $object) {
5050
foreach ($model->getRelations() as $relation) {
51-
// When a nullable BelongsTo relation wasn't loaded, we need to make sure to unset it if it has a default value.
51+
// When a relation with a default value wasn't loaded, we need to unset it.
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) {
53+
if ($relation instanceof BelongsTo && ! $relation->property->isNullable()) {
5454
continue;
5555
}
5656

57-
if (! $relation->property->isNullable()) {
57+
if (! $relation instanceof BelongsTo && ! $relation instanceof BelongsToMany) {
5858
continue;
5959
}
6060

0 commit comments

Comments
 (0)