Skip to content

Commit

Permalink
v11.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Oct 10, 2022
1 parent 2a7e74a commit 14335e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## v11

### v11.11.0

- Change `\Astrotomic\Translatable\Traits\Relationship::translation()` relation to use the new `ofMany` - [#297](https://github.com/Astrotomic/laravel-translatable/pull/297)

### v11.10.0

- Drop PHP7 support
Expand Down
3 changes: 2 additions & 1 deletion src/Translatable/Traits/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Astrotomic\Translatable\Traits;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

Expand Down Expand Up @@ -67,7 +68,7 @@ public function translation(): HasOne
->hasOne($this->getTranslationModelName(), $this->getTranslationRelationKey())
->ofMany([
$this->getTranslationRelationKey() => 'max',
], function ($query) {
], function (Builder $query): void {
$query->where($this->getLocaleKey(), $this->localeOrFallback());
});
}
Expand Down
6 changes: 5 additions & 1 deletion tests/TranslatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,10 @@ public function translation_relation(): void
$this->app->make('config')->set('translatable.use_fallback', true);
$this->app->setLocale('en');

$peas = factory(Vegetable::class)->create(['name:en' => 'Peas']);
$peas = factory(Vegetable::class)->create([
'name:en' => 'Peas',
'name:fr' => 'Pois',
]);

static::assertInstanceOf(VegetableTranslation::class, $peas->translation);
static::assertEquals('en', $peas->translation->locale);
Expand All @@ -819,6 +822,7 @@ public function translation_relation_can_use_fallback_locale(): void

$peas = factory(Vegetable::class)->create(['name:fr' => 'Pois']);

static::assertInstanceOf(VegetableTranslation::class, $peas->translation);
static::assertEquals('fr', $peas->translation->locale);
}

Expand Down

0 comments on commit 14335e3

Please sign in to comment.