title: Saving associated models in Cakephp 3
body: <p>I have a form that collects data about an Article, and I want to save that data, as well as for a model called Abstract, where an Article hasMany Abstracts.  My models look like this:</p>
  
  <pre><code>namespace App\Model\Table;
  
  use Cake\ORM\Table;
  use Cake\Validation\Validator;
  
  class AbstractsTable extends Table
  {
  public function initialize(array $config)
  {
      $this-&gt;belongsTo('Articles');
  }
  
  public function validationDefault(Validator $validator)
  {
      $validator
          -&gt;notEmpty('body');
      return $validator;
  }
  }
  </code></pre>
  
  <p>And </p>
  
  <pre><code>namespace App\Model\Table;
  
  use Cake\ORM\Table;
  use Cake\Validation\Validator;
  
  class ArticlesTable extends Table
  {
      public function initialize(array $config)
      {
          $this-&gt;addBehavior('Timestamp');
          $this-&gt;hasMany('Abstracts');
      }
  
  public function validationDefault(Validator $validator)
      {
          $validator  -&gt;notEmpty('category')
          return $validator;
      }
  }
  </code></pre>
  
  <p>My input form has a field named 'abstracts.body', and in my ArticlesController I have this function:</p>
  
  <pre><code>  public function add()
    {
            $data = $this-&gt;request-&gt;data;
            $article = $this-&gt;Articles-&gt;newEntity($data, [
                              'associated' =&gt; ['Abstracts']
                      ]);
           if ($this-&gt;request-&gt;is('post')) {
                    $article-&gt;user_id = $this-&gt;Auth-&gt;user('id');
                    $data['abstracts']['user_id'] = $article-&gt;user_id;
                    $data['abstracts']['approved'] = 0;
                    $article = $this-&gt;Articles-&gt;patchEntity($article, $data, [ 
                                  'associated' =&gt; ['Abstracts']
                            ]);
  
              if ($this-&gt;Articles-&gt;save($article, [ 'validate' =&gt; false,
                                                     'associated' =&gt; ['Abstracts']
                                                   ]) )
                   {
                           $this-&gt;Flash-&gt;success(__('Your article has been saved.'));
                           return $this-&gt;redirect(['action' =&gt; 'index']);
                   }
            $this-&gt;Flash-&gt;error(__('Unable to add your article.'));
            }
            $this-&gt;set('article', $article);
    }
  </code></pre>
  
  <p>My Abstracts table is pretty straightforward:</p>
  
  <pre><code>CREATE TABLE 'abstracts' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'article_id' INTEGER , 'user_id' INTEGER , 'body' TEXT, 'approved' BOOLEAN )
  </code></pre>
  
  <p>From debugging I can see that I have the correct 'abstracts' array within my $data (in add()), but it doesn't appear to ever try to save it to the database.  Can someone please point out my error?  Thanks!</p>