Answer the question
In order to leave comments, you need to log in
Does the ->with() construct cause a memory leak in Laravel?
Hello.
There is a request like this:
$products->joinRelations('categories')->with('products')->whereNotNull('category_id')->groupBy('category_id')->getCache(['product_categories.*']);
Answer the question
In order to leave comments, you need to log in
Rewrote it like this:
public function scopeGetCategories($query){
$categories = clone $query;
return $categories->joinRelations('categories')
->selectRaw('*, count(`product_category_values`.`product_id`) as products_count')
->whereNotNull('category_id')->groupBy('category_id')
->getCache(['product_categories.*']);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question