1.3: fix N+1 in getTranslation by using eager-loaded collection

This commit is contained in:
parsa aghaei 2026-06-23 18:10:22 +03:30
parent 28c7a317e5
commit 1dc72d8563
3 changed files with 9 additions and 0 deletions

View File

@ -25,6 +25,9 @@ public function translations()
*/
public function getTranslation($locale)
{
if ($this->relationLoaded('translations')) {
return $this->translations->firstWhere('locale', $locale);
}
return $this->translations()->where('locale', $locale)->first();
}

View File

@ -25,6 +25,9 @@ public function translations()
*/
public function getTranslation($locale)
{
if ($this->relationLoaded('translations')) {
return $this->translations->firstWhere('locale', $locale);
}
return $this->translations()->where('locale', $locale)->first();
}

View File

@ -33,6 +33,9 @@ public function translations()
*/
public function getTranslation($locale)
{
if ($this->relationLoaded('translations')) {
return $this->translations->firstWhere('locale', $locale);
}
return $this->translations()->where('locale', $locale)->first();
}