title: CakePHP 3 : multi level association
body: <p>I have 3 tables, <code>categories</code>, <code>products</code> and <code>seller_products</code> and their associations are 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;hasMany('SellerProducts', [
      'foreignKey' =&gt; 'product_id'
  ]);
  
  $this-&gt;belongsTo('Categories', [
      'foreignKey' =&gt; 'category_id',
      'joinType' =&gt; 'INNER'
  ]);
  </code></pre>
  
  <p><strong>SellerProductsTable.php</strong></p>
  
  <pre><code>$this-&gt;belongsTo('Products', [
      'foreignKey' =&gt; 'product_id',
      'joinType' =&gt; 'INNER'
  ]);
  </code></pre>
  
  <p>Now, In the <code>view</code> of <code>categories</code> (<code>site.com/categories/view/2</code>), I have to select all products data from <code>products</code> and <code>sellerProducts</code> where products belongs to category id and also exists in sellerProducts.
  ie.,</p>
  
  <pre><code>products.category_id = $id AND sellerProducts.product_id = Products.id
  </code></pre>
  
  <p>Is there any easy way in CakePHP 3 to get the result ?</p>
  
  <blockquote>
    <p>Edit 2</p>
  </blockquote>
  
  <p>This is what I'm trying. In <code>view()</code> action of <code>CategoriesController.php</code></p>
  
  <pre><code>$this-&gt;loadModel('Products');
          $sellerProducts = $this-&gt;Products-&gt;find('all', [
            'conditions' =&gt; [
              'category_id' =&gt; $id
            ],
            'joins' =&gt; [
                'table' =&gt; 'SellerProducts',
                'alias' =&gt; 'SellerProducts',
                'type' =&gt; 'INNER',
                'conditions' =&gt; [
                  'SellerProducts.product_id' =&gt; 'Products.id',
                  'stock &gt;' =&gt; 0
                ]
              ]
          ]);
          debug($sellerProducts);
          foreach($sellerProducts as $a) {
            debug($a);
          }
  </code></pre>
  
  <p>on <code>debug</code> it gives only the data from <code>Products</code> table but not from <code>SellerProducts</code></p>