0

I'm working on the database locking to ensure the safe data transactions in a multi-user participation.

The machine is installed with Passenger.

After I added the 'lock_version'(integer), the record no long is able to be modified through console.

Let's say,

lesson = Lesson.find(1)
lesson.start_time = Time.now
lesson.save 

=> then, ActiveRecord::StaleObjectError: Attempted to update a stale object: Lesson

But, with a very rare chance, a column is saved, which makes me confused a lot.

The rails version is 4.2.8

Many thanks over many thoughts..!

Best

Sungpah Lee
  • 1,003
  • 1
  • 13
  • 31
  • Especially, data will not be updated in accordance with cronjob commands. So console mode functions should all be guaranteed to work properly, which is not my case. – Sungpah Lee May 29 '19 at 07:47

1 Answers1

0

SO it turns out that in order to use Optimistic Locking, I should've added lock_version with the initial value 0 (integer), not null. Although in Rails console record shows 0, but in the database it actually was null. !

Sungpah Lee
  • 1,003
  • 1
  • 13
  • 31