I have a query which i am executing directly using connection manager like
$connection = ConnectionManager::get('default');
$sizes = $connection->execute('SELECT s.name size_name, s.id size_id, tp.price
FROM toppings t
INNER JOIN `sizes` s on s.category_id = t.category_id
LEFT JOIN `toppings_prices` tp ON tp.topping_id = t.id AND tp.size_id = s.id
WHERE t.id= :id', ['id' => $id])->fetchAll('assoc');
In this case Sizes
and Toppings
have many to many relation and the assocaitions are defined as per CakePHP 3 docu like in ToppingTable
i have defined the relation like
$this->belongsToMany('Sizes', [
'foreignKey' => 'topping_id',
'targetForeignKey' => 'size_id',
'joinTable' => 'toppings_prices'
]);
The above query is defined in ToppingsController’s edit method.
Is there are better way to acive the same results as from the above query?