vendredi 12 octobre 2018

Ruby: Will pessimist lock (self.lock!) work using update_all?

I don't want to use save! method, will pessimist lock (self.lock!) work using the update_all method?

lock! using save! method.

Account.transaction do
  self.lock!
  account1 = Account.find(...)
  account1.balance -= 100
  account1.save!
end

lock! using update_all method.

Account.transaction do
  self.lock!
  attributes["balance"] = recalculate_balance
  Account.where(:id => self.id).update_all(attributes)
end

Aucun commentaire:

Enregistrer un commentaire