【发布时间】:2020-10-19 16:28:23
【问题描述】:
with_lock 是锁定块中的所有模型还是仅锁定模型本身?例如以下是with_lock 中的所有item 模型被锁定还是只是entry 模型被锁定?
class Entry < ApplicationRecord
enum state: [:pending, :posted]
has_many :items, dependent: :destroy
def post!
with_lock do
return unless pending?
items.each { |i| i.post! }
self.posted!
end
end
end
【问题讨论】:
标签: ruby-on-rails postgresql activerecord locking pessimistic-locking