Rails 3 Column

Is it possible to lock the database table. MySQL example:

LOCK TABLES users WRITE

.. using some native ActiveRecord methods?

+7
source share
2 answers

This is not supported by ActiveRecord, you will have to start it manually using

ActiveRecord::Base.connection.execute("LOCK TABLES users WRITE") 

You can check out this discussion at ruby-forum.com for more information.

+9
source
 Pass :lock => true to ActiveRecord::Base.find to obtain an exclusive lock on the selected rows Pass :lock => 'some locking clause' to give a database-specific locking clause of your own such as 'LOCK IN SHARE MODE' or 'FOR UPDATE NOWAIT 

For more details see http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html

0
source

All Articles