title: Cakephp 3, Updating associated belongsto Data
body: <p>So I have 2 models: Plugins and Imports.
  The association is Plugins hasOne Imports:</p>
  
  <pre><code>$this-&gt;hasOne('Imports', [
      'foreignKey' =&gt; 'plugin_id'
  ]);
  </code></pre>
  
  <p>and Imports belongsTo Plugins:</p>
  
  <pre><code>$this-&gt;belongsTo('Plugins', [
      'foreignKey' =&gt; 'plugin_id',
      'joinType' =&gt; 'INNER'
  ]);
  </code></pre>
  
  <p>My plugins-table dump looks like this:</p>
  
  <pre><code>CREATE TABLE `plugins` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `type` varchar(50) NOT NULL,
    `pluginkey` varchar(100) NOT NULL,
    `pluginname` varchar(255) DEFAULT NULL,
    `description` text,
    `integrationinstructions` text,
    `date_available` datetime DEFAULT NULL,
    `date_last_changed` datetime DEFAULT NULL,
    `author` varchar(255) DEFAULT NULL,
    `version` varchar(10) DEFAULT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>and my imports table is:</p>
  
  <pre><code>CREATE TABLE imports (
      id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
      plugintype VARCHAR(50) NOT NULL,
      importedpluginkey VARCHAR(255) NOT NULL,
      imported DATETIME NULL DEFAULT NULL,
      plugin_id INT UNSIGNED NOT NULL,
      FOREIGN KEY plugin_key (plugin_id) REFERENCES plugins(id)
  );
  </code></pre>
  
  <p>Now i baked both controllers and everything works fine. I can save an import(will later be used to import xml files) and it is linked to a plugin.</p>
  
  <p>But now I want to let the Plugindata update through data I add in an import.</p>
  
  <p>For example let's say i have a Plugin called "sale" with the type Wordpress and the key "wp_sale". Now i want to update this plugin by adding an import. For example changing it's description or name.</p>
  
  <p>If i understand <a href="http://book.cakephp.org/3.0/en/orm/saving-data.html#saving-belongsto-associations" rel="nofollow">this</a> right, I would only need to pass the data I want to change in the plugins alongside the id.</p>
  
  <p>But when I check the patchEntity that is going to be safed the Plugin Entity is always '[new]'=> true, and the id I passed is gone.</p>
  
  <p>This is what my controller looks like:</p>
  
  <pre><code>public function add()
  {
      $import = $this-&gt;Imports-&gt;newEntity();
      if ($this-&gt;request-&gt;is('post')) {
          $import = $this-&gt;Imports-&gt;patchEntity($import, $this-&gt;request-&gt;data, ['associated' =&gt; ['Plugins']]);
          if ($this-&gt;Imports-&gt;save($import)) {
              $this-&gt;Flash-&gt;success(__('The import has been saved.'));
              return $this-&gt;redirect(['action' =&gt; 'index']);
          } else {
              $this-&gt;Flash-&gt;error(__('The import could not be saved. Please, try again.'));
          }
      }
      $plugins = $this-&gt;Imports-&gt;Plugins-&gt;find('list', ['limit' =&gt; 200]);
      $this-&gt;set(compact('import', 'plugins'));
      $this-&gt;set('_serialize', ['import']);
  }
  </code></pre>
  
  <p>And this is what my form looks like:</p>
  
  <pre><code>echo $this-&gt;Form-&gt;input('plugintype');
  echo $this-&gt;Form-&gt;input('importedpluginkey');
  echo $this-&gt;Form-&gt;input('imported');
  echo $this-&gt;Form-&gt;input('plugin_id', ['options' =&gt; $plugins]);
  echo $this-&gt;Form-&gt;input('plugin.pluginkey');
  echo $this-&gt;Form-&gt;input('plugin.type');
  echo $this-&gt;Form-&gt;input('plugin.id', ['value' =&gt; 1]);
  </code></pre>
  
  <p>I gave the plugin.id the value 1 just for the sake of testing, because I wanted to pass an id for the Plugin.</p>
  
  <p>My postdata looks like this:</p>
  
  <pre><code>[
      'plugintype' =&gt; 'wordpress',
      'importedpluginkey' =&gt; 'wp_sale',
      'imported' =&gt; [
          'year' =&gt; '2015',
          'month' =&gt; '11',
          'day' =&gt; '24',
          'hour' =&gt; '10',
          'minute' =&gt; '38'
      ],
      'plugin_id' =&gt; '1',
      'plugin' =&gt; [
          'pluginkey' =&gt; 'wp_sale',
          'type' =&gt; 'wordpress',
          'id' =&gt; '1'
      ]
  ]
  </code></pre>
  
  <p>And the patched Entity looks like this:</p>
  
  <pre><code>object(App\Model\Entity\Import) {
  
      'plugintype' =&gt; 'wordpress',
      'importedpluginkey' =&gt; 'wp_sale',
      'imported' =&gt; object(Cake\I18n\Time) {
  
          'time' =&gt; '2015-11-24T11:04:00+0000',
          'timezone' =&gt; 'UTC',
          'fixedNowTime' =&gt; false
  
      },
      'plugin_id' =&gt; (int) 1,
      'plugin' =&gt; object(App\Model\Entity\Plugin) {
  
          'pluginkey' =&gt; 'wp_sale',
          'type' =&gt; 'wordpress',
          '[new]' =&gt; true,
          '[accessible]' =&gt; [
              '*' =&gt; true
          ],
          '[dirty]' =&gt; [
              'pluginkey' =&gt; true,
              'type' =&gt; true
          ],
          '[original]' =&gt; [],
          '[virtual]' =&gt; [],
          '[errors]' =&gt; [],
          '[repository]' =&gt; 'Plugins'
  
      },
      '[new]' =&gt; true,
      '[accessible]' =&gt; [
          '*' =&gt; true
      ],
      '[dirty]' =&gt; [
          'plugintype' =&gt; true,
          'importedpluginkey' =&gt; true,
          'imported' =&gt; true,
          'plugin_id' =&gt; true,
          'plugin' =&gt; true
      ],
      '[original]' =&gt; [],
      '[virtual]' =&gt; [],
      '[errors]' =&gt; [],
      '[repository]' =&gt; 'Imports'
  
  }
  </code></pre>
  
  <p>Many Questions on this site are about association saving. But what i want is update associated data when adding new data in the import model.</p>
  
  <p>The reasoning behind it is, that I want to be able to update my Plugins without editing everyone of them, and just use the xml import.</p>
  
  <p>If the Question still is unclear feel free to ask and I will explain myself further. Thanks in advance!</p>
  
  <p><strong>Edit: To be clear, I basically need to change the data of a plugin using the import controller.</strong></p>
  
  <p><strong>I now got the plugin entity in another function now, and i can save that with the import entity. However, it doesnt change anything in the plugin, so basically that does nothing.</strong></p>