`translations` relationship is fetched even if it's not eager loaded.
MohammedElattar opened this issue · comments
Mohamed Attar commented
-
in
ProductController
, I eager load translation relationship, but when I usewhenLoaded
in a resource with specifying a
default value for translation, it causes N+1 queries.'translation' => $this->whenLoaded( 'translation', new ProductTranslationResource($this->translation) ), 'translations' => $this->whenLoaded( 'translations', ProductTranslationResource::collection($this->translations) ),
-
but it works if I don't pass a default value in
whenLoaded
method or using the following code:if($this->relationLoaded('translation')){ $resource['translation'] = new ProductTranslationResource($this->translation); } if($this->relationLoaded('translations')){ $resource['translations'] = ProductTranslationResource::collection($this->translations); }
Great Work. ❤
github-actions commented
This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days