如果 $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);
uj5u.com熱心網友回復:
如果product_id&沒有重復條目,此解決方案將回傳具有所有屬性值的 product_ids property_option_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');
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/394697.html
