Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord: How do I add NOLOCK?

Tags:

activerecord

I need to add "WITH NOLOCK" when using ActiveRecord? I know there is a way to do it nHibernate, but couldn't figure this out in ActiveRecord.

Thank you for your help. Regards,

like image 399
Liam Avatar asked Oct 28 '10 21:10

Liam


People also ask

How do you lock in rails?

Just add a lock_version column to the table you want to place the lock and Rails will automatically check this column before updating the record. Pessimistic locking assumes that database transaction conflict is very likely to happen. It locks the record until the transaction is done.

What is ActiveRecord in Ruby on Rails?

1 What is Active Record? Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.

What does ActiveRecord base do?

ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending. Edit: as Mike points out, in this case ActiveRecord is a module...

What is lock in Ruby?

Locking in a database means that no two or more sessions can update the same record at the same time until the lock is released. In this article we will discuss two main types of locking in Ruby on Rails; Optimistic Locking and Pessimistic Locking.


2 Answers

Not to revive an old post. But there is an option to lock per query rather than setting it in the model.

For Example:

Account.where("name = 'shugo'").lock(true).first

Check out this link for more info. http://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html

like image 143
Jonny B Avatar answered Sep 28 '22 02:09

Jonny B


I know this is old, but here is the answer:

criteria.SetLockMode(NHibernate.LockMode.None);
like image 45
Justin Avatar answered Sep 28 '22 02:09

Justin