Skip to content

Commit

Permalink
Merge pull request #424 from rbngzlv/remove-relation-key-on-dirty
Browse files Browse the repository at this point in the history
Fix regression trying to save empty translations
  • Loading branch information
Gummibeer authored Aug 26, 2024
2 parents 3147f70 + 1596192 commit 30ef101
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Translatable/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ protected function isTranslationDirty(Model $translation): bool
{
$dirtyAttributes = $translation->getDirty();
unset($dirtyAttributes[$this->getLocaleKey()]);
unset($dirtyAttributes[$this->getTranslationRelationKey()]);

return count($dirtyAttributes) > 0;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,25 @@ public function empty_translated_attribute(): void
self::assertNull($vegetable->name);
}

#[Test]
public function empty_translations_are_not_saved(): void
{
$vegetable = new Vegetable();
$vegetable->fill([
'en' => [],
'de' => ['name' => 'Erbsen'],
]);

$vegetable->save();

self::assertDatabaseHas('vegetable_translations', [
'locale' => 'de',
'name' => 'Erbsen',
]);

self::assertDatabaseMissing('vegetable_translations', ['locale' => 'en']);
}

#[Test]
public function numeric_translated_attribute(): void
{
Expand Down

0 comments on commit 30ef101

Please sign in to comment.