Rails postgresql how to set transaction isolation level to serializable

后端 未结 3 719
醉话见心
醉话见心 2021-01-06 18:08

I have a Comment model which belongs_to a Topic model. On the Comment model, I have a before_create callback

def on_create
  Topic.transaction(:require_new =         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-06 18:58

    As of Rails 4, #transaction provides an :isolation option:

    If your database supports setting the isolation level for a transaction, you can set it like so:

    Post.transaction(isolation: :serializable) do
      # ...
    end
    

提交回复
热议问题