Why does activerecord optimistic locking work only once per row? -


Anyhow, I always get on Friday.

My first question was in relation to the same problem, but I can now narrow down a few things:

I am playing with this whole day, to understand it I am trying. I have a table with a lock_version column, which is specified:

  add_column: jobs,: lock_version,: integer,: default = & gt; 0  

And I do something like this:

  foo = job.create! First = Job.find (foo.id) II = Job.find (foo.id)  

I again confirm that the first and the second see the same object - identical to their ID And I see that line in the database using the mysql command-line tool.

  first.some_attribute_field = 'first' second.some_attribute_field = 'second' first.save second.save  

No problem yet I have an ActiveRecord: : I get the StaleObjectError exception correctly. However :

  first = job.find (foo.id) second = job.fund (foo.id) first.some_attribute_field = 'first' second.some_attribute_field = 'Second' first. Second Savita  

... and nothing happens. It has come to know that only once I treat the right (thrown exception), the first and the second of the lock_version is 0. After saving it first, it is not 0 again. What's on the earth?

I am using Ruby 1.8.6 and active record 2.2.2

thanks ...

When you first call, the value of" some_attribute_field "is already equal to" before ", activerecord knows it, so it does not update lock_version The DB did not increase. In the second trial, try to change the value for something other than "first" so that it is different from what is in DB.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -