title: cakephp 3.x Saving Nested (deep) Association
body: <p>I have product data coming from a 3rd party service call that I then create an object from and save to my MySQL DB. My models are as follows:</p>
  
  <p>'products' hasMany>> 'product_skus' hasMany>> 'product_sku_attributes'</p>
  
  <p><a href="https://i.stack.imgur.com/KDQZR.png" rel="nofollow noreferrer">table relationships</a> </p>
  
  <p>In my ProductsTable.php initialize() method I have:</p>
  
  <pre><code>$this-&gt;hasMany('ProductSkus', [
      'foreignKey' =&gt; 'product_no',
      'dependent' =&gt; true,
  ]);
  </code></pre>
  
  <p>In my ProductSkusTable.php initialize() method I have:</p>
  
  <pre><code>$this-&gt;hasMany('ProductSkuAttributes', [
      'foreignKey' =&gt; 'product_sku_id',
      'bindingKey' =&gt; 'id',
      'propertyName' =&gt; 'product_sku_attributes',
      'dependent' =&gt; true,
  ]);
  </code></pre>
  
  <p>My controller:</p>
  
  <pre><code>$products = TableRegistry::get('Products');
  $entity = $products-&gt;newEntity($product_data[0]);
  $products-&gt;save($entity, [
      'associated' =&gt; [
          'ProductSkus',
          'ProductSkus.ProductSkuAttributes',
      ]
  ]);
  </code></pre>
  
  <p>Here's is the relevant snippet from my entity debug:</p>
  
  <pre><code>'product_skus' =&gt; [
      (int) 0 =&gt; object(App\Model\Entity\ProductSkus) {
  
          'sku' =&gt; 'BDS1401H',
          'sku_price' =&gt; (float) 366.76,
          'sku_weight' =&gt; (float) 38.1,
          'sku_img_main' =&gt; '',
          'sku_img_large' =&gt; '',
          'sku_img_default' =&gt; false,
          'is_default' =&gt; true,
          'product_sku_attributes' =&gt; [
              (int) 0 =&gt; [
                  'product_no' =&gt; (int) 23200,
                  'sku' =&gt; 'BDS1401H',
                  'attribute_name' =&gt; 'Front Sway Bar Links',
                  'option_name' =&gt; 'Stock'
              ],
              (int) 1 =&gt; [
                  'product_no' =&gt; (int) 23200,
                  'sku' =&gt; 'BDS1401H',
                  'attribute_name' =&gt; 'Shock Options',
                  'option_name' =&gt; 'NX2 Series'
              ],
              (int) 2 =&gt; [
                  'product_no' =&gt; (int) 23200,
                  'sku' =&gt; 'BDS1401H',
                  'attribute_name' =&gt; 'Steering Stabilizer Options',
                  'option_name' =&gt; 'Stock'
              ]
          ],
          '[new]' =&gt; true,
          '[accessible]' =&gt; [
              '*' =&gt; true,
              'id' =&gt; true
          ],
          '[dirty]' =&gt; [
              'sku' =&gt; true,
              'sku_price' =&gt; true,
              'sku_weight' =&gt; true,
              'sku_img_main' =&gt; true,
              'sku_img_large' =&gt; true,
              'sku_img_default' =&gt; true,
              'is_default' =&gt; true,
              'product_sku_attributes' =&gt; true
          ],
          '[original]' =&gt; [],
          '[virtual]' =&gt; [],
          '[errors]' =&gt; [],
          '[invalid]' =&gt; [],
          '[repository]' =&gt; 'ProductSkus'
  
      },
      (int) 1 =&gt; object(App\Model\Entity\ProductSkus) { ...
  </code></pre>
  
  <p>I doubled checked, and all my fields are set as accessible in my table entity classes. Also, at this point I'm only trying to save one product record for simplicity, hence $products->newEntity().</p>
  
  <p>My data is saving to 'products' and 'product_skus' tables without problem, but not to 'product_sku_products'. Can anyone see what the problem is? Is it because I'm not using the same foreignKey?</p>
  
  <p>Please let me know what else I can provide for clarity.</p>