Cakephp 3 queryBuilder for many to many relations

I have a query which i am executing directly using connection manager like

$connection = ConnectionManager::get('default');
$sizes = $connection->execute('SELECT size_name, 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 = AND tp.size_id =
         WHERE :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?

If Sizes and Topping has many-to-many relationship than you should define the association not only for Sizes but for Toppings also.

Than you can use find()->matching() as it is described in the manual

The best place to put these calls is in model files if you are following the fat model principle.

Thank you very much for your response. Yes I have defined many ro many Relation for both Sizes and Toppings.

If I want to add a New topping i want to Display all available Sizes in Topping’s add.ctp.

Will match() method will do the Trick?

Yes, sure. matching() is the right way to do this