[英]laravel, how to select with all values
如果 $property_values 中有任何 property_option_id,則 whereIn 返回 product_id。 如果它全部來自 $property_values,如何返回?
/*
arr int $property_values
db property_product_values
id, product_id, property_option_id
*/
$query->select('property_values.product_id')
->from('property_values')
->whereColumn('property_values.product_id', 'products.id')
->whereIn("property_values.property_option_id", $property_values);
如果product_id
和property_option_id
沒有重復條目,此解決方案將返回具有所有屬性值的 product_id。
$query->select('property_values.product_id')
->from('property_values')
->whereIn('property_values.property_option_id', $property_values)
->groupBy('property_values.product_id')
->having(DB::raw('count(product_id)'), '>=', count($property_values))
->pluck('property_values.product_id');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.