title: cakephp 3 matching only if row exists
body: <p>I'm using CakePHP 3.2.</p>
  
  <p>I have three tables <code>categories</code>, <code>products</code> and <code>seller_products</code></p>
  
  <p>I want to retrieve data from all tables, where <code>seller_products.stock &gt; 0</code> and <code>seller_products.status = 1</code> also GROUP BY <code>categories</code>.</p>
  
  <p>This code is working fine</p>
  
  <pre><code>$pros1 = $this-&gt;Products-&gt;Categories-&gt;find()
      -&gt;where([
      ])
      -&gt;select(['Categories.id', 'Categories.title'])
      -&gt;distinct(['Categories.id'])
      -&gt;contain([
          'Products' =&gt; ['conditions' =&gt; ['status' =&gt; 1]], 'Products.SellerProducts',
      ])
      -&gt;matching('Products.SellerProducts', function(\Cake\ORM\Query $q) {
      return $q-&gt;where(['SellerProducts.stock &gt;' =&gt; 0, 'SellerProducts.status' =&gt; 1]);
  });
  </code></pre>
  
  <p>an their association is</p>
  
  <pre><code>$categories-&gt;hasMany('Products', [
     'foreignKey' =&gt; 'category_id'
  ]);
  $products-&gt;hasMany('SellerProducts, [
     'foreignKey' =&gt; 'product_id'
  ]);
  </code></pre>
  
  <p>Now, the problem is.</p>
  
  <p><strong>This query is returning even those products which does not exits in <code>SellerProducts.product_id</code></strong></p>
  
  <p>How to get only those products which has existence in <code>SellerProducts</code> and meet the conditions as given in matching ?</p>