title: multi level association and filter in cakephp
body: <p>I'm new to stackoverflow and this is my first question.
  Please pardon me for any errors in question.</p>
  
  <p>I'm working in CakePHP 3.2</p>
  
  <p>I have <code>categories</code>, <code>products</code>, <code>seller_products</code> table and their association is like 
  <strong>CategoriesTable.php</strong></p>
  
  <pre><code>$this-&gt;hasMany('Products', [
     'foreignKey' =&gt; 'category_id'
  ]);
  </code></pre>
  
  <p><strong>ProductsTable.php</strong></p>
  
  <pre><code>$this-&gt;belongsTo('Categories', [
       'foreignKey' =&gt; 'category_id',
       'joinType' =&gt; 'INNER'
  ]);
  $this-&gt;hasMany('SellerProducts', [
      'foreignKey' =&gt; 'product_id'
  ]);
  </code></pre>
  
  <p><strong>SellerProducts.php</strong></p>
  
  <pre><code>$this-&gt;belongsTo('Products', [
      'foreignKey' =&gt; 'product_id',
      'joinType' =&gt; 'INNER'
  ]);
  </code></pre>
  
  <p><strong>Table Association</strong></p>
  
  <p><code>products</code> table has <code>category_id</code> as foreign key referencing <code>categories</code> table and <code>seller_products</code> has <code>product_id</code> as foreign key referencing <code>products</code> table</p>
  
  <p><code>seller_products</code> has column <code>stock</code>.</p>
  
  <p><strong>What I want to do is to select all categories containing associated products whose stock in seller_products is > 0</strong></p>
  
  <p>This is what I have done </p>
  
  <pre><code>$pros1 = $this-&gt;Products-&gt;Categories-&gt;find()
    -&gt;where([
       'Products.SellerProducts.stock &gt;' =&gt; 0
    ])
    -&gt;contain([
       'Products.SellerProducts', 'Subcategories', 'ProductTypes'
    ]);
  </code></pre>
  
  <p>but it is giving error as</p>
  
  <pre><code>Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Products.SellerProducts.stock' in 'where clause' 
  </code></pre>