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,
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.
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.
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...
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.
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
I know this is old, but here is the answer:
criteria.SetLockMode(NHibernate.LockMode.None);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With