Ruby on rails Ruby:悲观锁(self.lock!)会使用update\u all工作吗?
我不想使用Ruby on rails Ruby:悲观锁(self.lock!)会使用update\u all工作吗?,ruby-on-rails,ruby,ruby-on-rails-3,race-condition,Ruby On Rails,Ruby,Ruby On Rails 3,Race Condition,我不想使用保存方法,悲观锁(self.lock!)会使用update\u all方法工作吗 锁使用保存方法 Account.transaction do self.lock! account1 = Account.find(...) account1.balance -= 100 account1.save! end Account.transaction do self.lock! attributes["balance"] = recalculate_balance
保存代码>方法,悲观锁(self.lock!)会使用update\u all
方法工作吗
锁代码>使用保存代码>方法
Account.transaction do
self.lock!
account1 = Account.find(...)
account1.balance -= 100
account1.save!
end
Account.transaction do
self.lock!
attributes["balance"] = recalculate_balance
Account.where(:id => self.id).update_all(attributes)
end
锁代码>使用update\u all
方法
Account.transaction do
self.lock!
account1 = Account.find(...)
account1.balance -= 100
account1.save!
end
Account.transaction do
self.lock!
attributes["balance"] = recalculate_balance
Account.where(:id => self.id).update_all(attributes)
end
Rails::VERSION::STRING=>“3.2.22.4”
是,update\u all
也会释放锁
但是:在您提供的代码中,您锁定了事务中的行。它不会释放此锁,因为事务仍在锁定此行。它将通过事务提交进行发布。是rails 3还是4?@SergioTulentsevruby-v ruby 2.3.7p456(2018-03-28修订版63024)[x86_64-linux]
这不是我要问的。@SergioTulentsev抱歉我的错误<代码>Rails::VERSION::STRING=>“3.2.22.4”