0%

laravel has和 wherehas的性能问题

#laravel orm 查询 奇慢无比。。。这是个坑啊

1
2
3
$products = Product::whereHas('colors', function ($q) use ($id) {
$q->where('photo', '<>', '')->where('colors.id', '=', $id);
})->paginate(8);

改为SQL:

1
2
$products = Product::
whereRaw('products.id in (select product_id from color_product where color_product.color_id = ? and color_product.photo <> "" )', [$id]);