You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
hi i have noticed that in scopeWithTranslation the second where for the default language is appended to the main query causing the query emitted by eloquent be similar to
*{external_id_field} in (x,y,z....) and locale={currentlocale} or locale={defaultlocale} . *
without parentization the correct query should be some thing like
*{external_id_field} in (x,y,z....) and( locale={current_locale} or locale={default_locale}) . *
using the wrong query in practice does not came with a wrong final result because the master records are filtered, but the performance are very bad ...
you'll find a possible correction of the query scope below
/**
* This scope eager loads the translations for the default and the fallback locale only.
* We can use this as a shortcut to improve performance in our application.
*
* @param Builder $query
*/
public function scopeWithTranslation(Builder $query)
{
$query->with(['translations' => function(Relation $q){
$q->where(function ($query) {
$query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $this->locale());
if ($this->useFallback()) {
return $query->orWhere($this->getTranslationsTable().'.'.$this->getLocaleKey(), $this->getFallbackLocale());
}
});
}]);
}
The text was updated successfully, but these errors were encountered:
raphaelsaunier
added a commit
to raphaelsaunier/laravel-translatable
that referenced
this issue
Nov 17, 2017
When using the `withTranslation` query scope along with country-based
locales, the generated query didn't include the country fallback (e.g.
`de-DE` should first fall back to `de` before using the fallback defined
in the configuration).
Also fixdimsav#241 by generating a WHERE IN clause instead chaining AND/ORs
raphaelsaunier
added a commit
to raphaelsaunier/laravel-translatable
that referenced
this issue
Nov 17, 2017
When using the `withTranslation` query scope along with country-based
locales, the generated query didn't include the country fallback (e.g.
`de-DE` should first fall back to `de` before using the fallback defined
in the configuration).
Also fixdimsav#241 by generating a WHERE IN clause instead chaining AND/ORs
raphaelsaunier
added a commit
to raphaelsaunier/laravel-translatable
that referenced
this issue
Nov 17, 2017
When using the `withTranslation` query scope along with country-based
locales, the generated query didn't include the country fallback (e.g.
`de-DE` should first fall back to `de` before using the fallback defined
in the configuration).
Also fixdimsav#241 by generating a WHERE IN clause instead chaining AND/ORs
hi i have noticed that in scopeWithTranslation the second where for the default language is appended to the main query causing the query emitted by eloquent be similar to
*{external_id_field} in (x,y,z....) and locale={currentlocale} or locale={defaultlocale} . *
without parentization the correct query should be some thing like
*{external_id_field} in (x,y,z....) and( locale={current_locale} or locale={default_locale}) . *
using the wrong query in practice does not came with a wrong final result because the master records are filtered, but the performance are very bad ...
you'll find a possible correction of the query scope below
The text was updated successfully, but these errors were encountered: