title: CakePHP v3: How to get patchEntity to update associations in request data
body: <p>I'm using <code>patchEntity()</code> to update hasMany associations and it works fine. My problem is not related to the data that is saved in the DB. My problem is that the association data stored in the entity variable goes out of sync...</p>
  
  <p>Notice in the method below that I have to do a second <code>get()</code> after the save to RE-read the data from the DB. If I remove this, the next view will show stale association data because patchEntity updates the foreign keys, but the actual association object is still the previous (from before the save).</p>
  
  <p>I wish there was a way to not make two DB queries in a row. Is this the intended behavior? Is there a better way to do it?</p>
  
  <pre><code>public function edit($id = null)
  {
      //1//////////////////////////////////////////
      $screen = $this-&gt;Screens-&gt;get($id, [
          'contain' =&gt; ['Blocks'=&gt;['Datasources'=&gt;['Agencies']]] 
      ]);
  
      if ($this-&gt;request-&gt;is(['patch', 'post', 'put'])) {
  
          $screen = $this-&gt;Screens-&gt;patchEntity(  $screen, 
                                                  $this-&gt;request-&gt;data, 
                                                  [
                                                      'associated'=&gt;['Blocks.Datasources']
                                                  ]
                                              );
          if ($this-&gt;Screens-&gt;save($screen)) {
  
              //2//////////////////////////////////////////
              #get the UPDATED properties... specifically, the associations don't get updated automatically by patchEntity above
              $screen = $this-&gt;Screens-&gt;get($id, [
                  'contain' =&gt; ['Blocks'=&gt;['Datasources'=&gt;['Agencies']]]
              ]);
  
              $this-&gt;Flash-&gt;success('The screen has been saved.');
          } else {
              $this-&gt;Flash-&gt;error('The screen could not be saved. Please, try again.');
          }
      }
  
      $this-&gt;set(compact('screen'));
  }
  </code></pre>