Update a HasMany records
<p>I am converting a working app from cakephp2 to cakephp3.  I'm struggling to get a form that updates hasMany records to work. </p>

<p>The app has the following structure: </p>

<p>MODELS:
    

<pre><code>use Cake\ORM\Table;
use Cake\Validation\Validator;

class AwardsTable extends Table
{
  public function initialize(array $config)
  {
   $this-&gt;hasMany('Levels', ['sort' =&gt; 'sort_order']);
  }
}


namespace App\Model\Entity;
use Cake\Auth\DefaultPasswordHasher;
use Cake\ORM\Entity;

class Award extends Entity
{
  protected $_accessible = [
    'name'            =&gt;  true,
    'url'             =&gt;  true,
    'organisation'    =&gt; true,
    'detail'          =&gt;  true,
    'logo'            =&gt;  true,
    'levels'          =&gt;  true,
    'Levels'          =&gt;  true
   ];

}
</code></pre>

<p>IN THE FORM:</p>

<pre><code>&lt;?= $this-&gt;Form-&gt;input("levels.$i.name",  'label'=&gt;false,'type'=&gt;'text','value' =&gt; $award-&gt;name]);?&gt;
&lt;?= $this-&gt;Form-&gt;input("levels.$i.id", ['value' =&gt; $award-&gt;id]); ?&gt;
</code></pre>

<p>CONTROLLER</p>

<pre><code>$this-&gt;Awards-&gt;patchEntity($award, $this-&gt;request-&gt;data, ['associated' =&gt; ['Levels']]);         
if ($this-&gt;Awards-&gt;save($award)) {
    $this-&gt;Flash-&gt;success(__('Your Award has been saved.'));
    $this-&gt;redirect(['action' =&gt; 'index']);
}
</code></pre>

<p>This seems inline with what is recommended here: <a href="http://book.cakephp.org/3.0/en/views/helpers/form.html#associated-form-inputs" rel="nofollow">http://book.cakephp.org/3.0/en/views/helpers/form.html#associated-form-inputs</a>  </p>

<p>I've tried a few variations with capitalisation &amp; pluralisation. The award data saves correctly but the associated levels data does not save. </p>

<p>What am I missing to get the has_many association data to save?</p>

<p>EDIT: Example Data array submitted:</p>

<pre><code>    2016-01-28 23:32:56 Error: Array
(
    [id] =&gt; 4
    [name] =&gt; test award
    [organisation] =&gt; test org
    [url] =&gt; http://www.example.com
    [detail] =&gt; 
    [levels] =&gt; Array
        (
            [0] =&gt; Array
                (
                    [name] =&gt; test 1
                    [id] =&gt; 4
                )

            [11] =&gt; Array
                (
                    [name] =&gt; test
                    [id] =&gt; 16
                )

        )

    [image] =&gt; Array
        (
            [name] =&gt; 
            [type] =&gt; 
            [tmp_name] =&gt; 
            [error] =&gt; 4
            [size] =&gt; 0
        )

)
</code></pre>