title: Why does activerecord optimistic locking work only once per row?
body: <p>Somehow, I always get these on Fridays.</p>
  
  <p>My earlier question was regarding the same problem, but I can now narrow things down a bit:</p>
  
  <p>I've been playing with this all day, trying to make sense of it.  I have a table with a lock_version colum, specified thus:</p>
  
  <pre><code>add_column :jobs, :lock_version, :integer, :default=&gt;0
  </code></pre>
  
  <p>And I do something like this:</p>
  
  <pre><code>foo = job.create!
  first = Job.find(foo.id)
  second = Job.find(foo.id)
  </code></pre>
  
  <p>I then verify that first and second refer to the same object - their ids are the same and I see that row in the database using the mysql command-line tool.</p>
  
  <pre><code>first.some_attribute_field = 'first'
  second.some_attribute_field = 'second'
  first.save
  second.save
  </code></pre>
  
  <p>no problem so far.  I correctly get an ActiveRecord::StaleObjectError exception.  <strong>HOWEVER</strong>:</p>
  
  <pre><code>first = Job.find(foo.id)
  second = Job.find(foo.id)
  first.some_attribute_field = 'first'
  second.some_attribute_field = 'second'
  first.save
  second.save
  </code></pre>
  
  <p>...and nothing happens.  It turns out that the only time I get correct (thrown exception) behavior is when first and second have a lock_version of 0.  After the first save, though, it is NEVER 0 again.  What on earth is up with this?</p>
  
  <p>I'm using ruby 1.8.6 and active record 2.2.2</p>
  
  <p>Thanks...</p>