title: Update ActiveRecord attribute with SQL function
body: <p>In rails, are you able to update a record's attribute with an evaluation of a SQL function?</p>
  
  <p>MySQL Table</p>
  
  <pre><code>| time_started        | time_to_execute |
  |---------------------------------------|
  | 2015-10-28 14:13:58 |      NULL       |
  </code></pre>
  
  <p>What I am trying to do:</p>
  
  <pre><code>update table set time_to_execute = TIME_TO_SEC(TIMEDIFF(NOW(), time_started))
  </code></pre>
  
  <p>through a model.</p>
  
  <hr>
  
  <p>I've tried to do this using the common attribute update methods to no avail.</p>
  
  <pre><code>c.update_attribute(:time_to_execute, 'TIME_TO_SEC(TIMEDIFF(NOW(), time_started))')
  c.update({:time_to_execute =&gt; 'TIME_TO_SEC(TIMEDIFF(NOW(), time_started))'})
  </code></pre>
  
  <h3>Is it possible to update attributes of an ActiveRecord model using SQL functions?</h3>
  
  <p>I know that I can accomplish this executing arbitrary SQL, or calculating diff between two <code>DateTime</code> ruby objects, but I'm wondering if this is possible via a model method.</p>