Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #23

Merged
merged 6 commits into from Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -11,7 +11,7 @@ defaults: &defaults
command: 'dockerize -wait tcp://localhost:3306 -timeout 1m'
- run:
name: 'Install MySQL-Client'
command: 'sudo apt-get update && sudo apt-get install -y mysql-client'
command: 'sudo apt-get update && sudo apt-get install -y mariadb-client'

- run:
name: 'MySQL Database'
Expand Down
15 changes: 8 additions & 7 deletions src/Translatable/Traits/Relationship.php
Expand Up @@ -63,15 +63,16 @@ public function getTranslationRelationKey(): string

public function translation(): HasOne
{
if ($this->useFallback() && ! $this->translations()->where('locale', $this->locale())->exists()) {
return $this
->hasOne($this->getTranslationModelName(), $this->getTranslationRelationKey())
->where('locale', $this->getFallbackLocale());
}

return $this
->hasOne($this->getTranslationModelName(), $this->getTranslationRelationKey())
->where('locale', $this->locale());
->where('locale', $this->localeOrFallback());
}

private function localeOrFallback()
{
return $this->useFallback() && ! $this->translations()->where('locale', $this->locale())->exists()
? $this->getFallbackLocale()
: $this->locale();
}

public function translations(): HasMany
Expand Down