Skip to content

Commit 1596192

Browse files
committed
Fix regression trying to save empty translations
After the change from #418 translations were always considered dirty
1 parent 695792b commit 1596192

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
@@ -763,6 +763,25 @@ public function empty_translated_attribute(): void
763763
self::assertNull($vegetable->name);
764764
}
765765

766+
#[Test]
767+
public function empty_translations_are_not_saved(): void
768+
{
769+
$vegetable = new Vegetable();
770+
$vegetable->fill([
771+
'en' => [],
772+
'de' => ['name' => 'Erbsen'],
773+
]);
774+
775+
$vegetable->save();
776+
777+
self::assertDatabaseHas('vegetable_translations', [
778+
'locale' => 'de',
779+
'name' => 'Erbsen',
780+
]);
781+
782+
self::assertDatabaseMissing('vegetable_translations', ['locale' => 'en']);
783+
}
784+
766785
#[Test]
767786
public function numeric_translated_attribute(): void
768787
{

0 commit comments

Comments
 (0)