Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do ActiveRecord locks have to occur inside a transaction?

Do ActiveRecord locks only work when they are inside of a transaction? If I open up two rails consoles and find a record then call lock! on that record I can still access the record from the other console.

like image 573
ThomYorkkke Avatar asked Oct 21 '25 19:10

ThomYorkkke


1 Answers

According to the docs, lock! does not include a transaction. with_lock does, though, and should prevents you from writing to (but not reading from) the locked record.

like image 130
Andrew Schwartz Avatar answered Oct 24 '25 11:10

Andrew Schwartz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!