title: Save data into 2 tables cakephp 3
body: <p>I am very new to Cakephp 3. I try to do saveAll function in Cakephp 3, but unsuccessful.</p>
  
  <p>I have 2 tables : Merchants and Users</p>
  
  <p>Relationship between this 2 tables as below:</p>
  
  <p>Users hasMany Merchants, 
  Merchants belongsTo Users</p>
  
  <p>I want the create a merchant's registration form that will insert the data to both tables.</p>
  
  <p>Can someone help me how to insert data into 2 different tables from 1 form using Cakephp 3?</p>
  
  <p>My code as below:</p>
  
  <pre><code> &lt;?= $this-&gt;Form-&gt;create($merchant); ?&gt;
  &lt;fieldset&gt;
      &lt;legend&gt;&lt;?= __('Add Merchant') ?&gt;&lt;/legend&gt;
      &lt;?php
          echo $this-&gt;Form-&gt;input('User.id');
          echo $this-&gt;Form-&gt;input('User.username');
          echo $this-&gt;Form-&gt;input('User.password');
          echo $this-&gt;Form-&gt;input('merchant_type_id', ['options' =&gt; $merchantTypes]);
          echo $this-&gt;Form-&gt;input('name');
          echo $this-&gt;Form-&gt;input('identity_number');
          echo $this-&gt;Form-&gt;input('phone_number');
      ?&gt;
  &lt;/fieldset&gt;
  &lt;?= $this-&gt;Form-&gt;button(__('Submit')) ?&gt;
  &lt;?= $this-&gt;Form-&gt;end() ?&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function registration()
  {
      $merchant = $this-&gt;Merchants-&gt;newEntity();
      if ($this-&gt;request-&gt;is('post')) {
          $merchant = $this-&gt;Merchants-&gt;patchEntity($merchant, $this-&gt;request-&gt;data, [
              'associated' =&gt; ['Users']
          ]);
          if ($this-&gt;Merchants-&gt;saveAll($merchant)) {
              $this-&gt;Flash-&gt;success('The merchant has been saved.');
              return $this-&gt;redirect(['action' =&gt; 'index']);
          } else {
              $this-&gt;Flash-&gt;error('The merchant could not be saved. Please, try again.');
          }
      }
      $users = $this-&gt;Merchants-&gt;Users-&gt;find('list', ['limit' =&gt; 200]);
      $merchantTypes = $this-&gt;Merchants-&gt;MerchantTypes-&gt;find('list', ['limit' =&gt; 200]);
      $this-&gt;set(compact('merchant', 'users', 'merchantTypes'));
  }
  </code></pre>
  
  <p>Your helps is very appreciated. Thanks.</p>