Skip to content

Commit 30ef101

Browse files
authored
Merge pull request #424 from rbngzlv/remove-relation-key-on-dirty
Fix regression trying to save empty translations
2 parents 3147f70 + 1596192 commit 30ef101

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Translatable/Translatable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ protected function isTranslationDirty(Model $translation): bool
347347
{
348348
$dirtyAttributes = $translation->getDirty();
349349
unset($dirtyAttributes[$this->getLocaleKey()]);
350+
unset($dirtyAttributes[$this->getTranslationRelationKey()]);
350351

351352
return count($dirtyAttributes) > 0;
352353
}

tests/TranslatableTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,25 @@ public function empty_translated_attribute(): void
778778
self::assertNull($vegetable->name);
779779
}
780780

781+
#[Test]
782+
public function empty_translations_are_not_saved(): void
783+
{
784+
$vegetable = new Vegetable();
785+
$vegetable->fill([
786+
'en' => [],
787+
'de' => ['name' => 'Erbsen'],
788+
]);
789+
790+
$vegetable->save();
791+
792+
self::assertDatabaseHas('vegetable_translations', [
793+
'locale' => 'de',
794+
'name' => 'Erbsen',
795+
]);
796+
797+
self::assertDatabaseMissing('vegetable_translations', ['locale' => 'en']);
798+
}
799+
781800
#[Test]
782801
public function numeric_translated_attribute(): void
783802
{

0 commit comments

Comments
 (0)