title: Copying one row's data to another row with Laravel's Eloquent (or Fluent)
body: <p>Here's the deal. I've set up my database with two tables that are more or less as follows (actually, my table is much more complex, but this is the gist):</p>
  
  <p><strong>TABLE `elements`</strong></p>
  
  <ul>
  <li>id</li>
  <li>data</li>
  </ul>
  
  <p><strong>TABLE `element_drafts`</strong></p>
  
  <ul>
  <li>id</li>
  <li>element_id</li>
  <li>data</li>
  </ul>
  
  <p>As you might be able to guess from the names, the second table contains rows that are drafts of rows in the first table. (Don't worry about recommending better ways to do the drafts =) my tables are more complex than shown, and having a drafts table is the best solution atm).</p>
  
  <p>I've set up a relationship between the two tables so that I can do things like this:</p>
  
  <pre><code>// Get all of the elements along with their draft rows
  $elements_with_drafts = Element::with('drafts')-&gt;all();
  </code></pre>
  
  <p>I'm also able to select only the elements that HAVE draft rows by doing this:</p>
  
  <pre><code>$elements_with_drafts = Element::with('drafts')
      -&gt;whereIn('id', function($query)
      {
          $query-&gt;select('element_id')-&gt;from('element_drafts');
      })
      -&gt;get();
  </code></pre>
  
  <p>But there's one thing that I'd like to do that I can't figure out: copying the draft values to their parent element.</p>
  
  <h2>In the end, my goal is to copy over all of the element_drafts['data'] values to their parent element['data'] field via a single query.</h2>
  
  <p>I'm not totally sure that this is even possible. Is it?</p>
  
  <p>My guess is that somehow it might be done like this:</p>
  
  <pre><code>$elements_with_drafts = Element::with('drafts')
      -&gt;whereIn('id', function($query)
      {
          $query-&gt;select('element_id')-&gt;from('element_drafts');
      })
      -&gt;update(array("data" =&gt; function($query)
      {
          // Somehow select the draft value?
      });
  </code></pre>
  
  <p>I feel like I'm really close, but I'm not quite sure how to do what I want. Any ideas?</p>
  
  <p>Note: obviously this could be accomplished relatively easily with a <code>foreach</code> loop, but I'm hoping for a solution that is just a single query.</p>