CakePHP 3.x: multiple records from one form into multiple tables
<p>I want to fill records from <strong>one</strong> form into <strong>several</strong> tables but I can´t find any solution. Can you give me a little example please?</p>

<p>Bake created this code for me.</p>

<p>Table: </p>

<pre><code>$this-&gt;table('order');
        $this-&gt;displayField('name');
        $this-&gt;primaryKey('id');

        $this-&gt;belongsTo('Clients', [
            'foreignKey' =&gt; 'client_id',
            'joinType' =&gt; 'INNER'
        ]);
</code></pre>

<p>Controller:</p>

<pre><code> $order = $this-&gt;Orders-&gt;newEntity();
                if ($this-&gt;request-&gt;is('post')) {
                    $order = $this-&gt;Order-&gt;patchEntity($order, $this-&gt;request-&gt;data);
                    if ($this-&gt;Orders-&gt;save($order)) {
                       $this-&gt;Flash-&gt;success(__('Order has been saved.'));
                       return $this-&gt;redirect(['action' =&gt; 'index']);
                    } else {
                      $this-&gt;Flash-&gt;error(__('Try again.'));
                    }
                }

        $clients = $this-&gt;Orders-&gt;Clients-&gt;find('list', ['limit' =&gt; 200]);  
        $this-&gt;set(compact('order', 'clients'));
        $this-&gt;set('_serialize', ['order']);
</code></pre>

<p>Template:</p>

<pre><code>$this-&gt;Form-&gt;create($order)
echo $this-&gt;Form-&gt;input('number', array('label' =&gt; ('Number')));
/** more inputs **/

$this-&gt;Form-&gt;create($client)
echo $this-&gt;Form-&gt;input('name');
/** more inputs **/

$this-&gt;Form-&gt;button(__('Submit');
$this-&gt;Form-&gt;end();
</code></pre>

<p>Thanks in advance.</p>