我正在尝试重写CakePHP 3中的现有网站
我有一个查询
SELECT *
FROM
(
SELECT p.name, p.description, p.category_id, s.name as size_name, p.id, s.id as size_id
FROM products p
INNER JOIN sizes s ON s.category_id = p.category_id
WHERE p.id = 588
) T1
LEFT JOIN
(
SELECT pp.product_id, pp.price, pp.id, pp.size_id
FROM products_prices pp
) T2
ON T1.size_id = T2.size_id AND T1.id = T2.product_id
产品belongsTo
类别和类别hasMany
因此,如果产品x
belongsTo
类别A
和类别A
有4种尺寸。这意味着products_prices
每个尺码将有4个价格
如何在Cakephp 3查询构建器中优化或重写此查询?