Lui*_*spo 1 transactions ruby-on-rails mongoid
我在我的应用程序中使用Rails 4.1.4和Mongoid.
我只是想知道是否有办法在Rails中使用Mongoid以原子方式执行块事务.
为了弄清楚,假设我有这个:
some_model_instance = SomeModel.find(some_id)
some_model_instance.some_attribute = "Some Attribute Value"
some_model_instance.save
other_model_instance = OtherModel.find(other_id)
other_model_instance.other_attribute = "Other Attribute Value"
other_model_instance.save
Run Code Online (Sandbox Code Playgroud)
我想将该代码包装在单个原子事务中,我的意思是,如果出现问题,我不希望将两个实例(some_model_instance,other_model_instance)都保存到数据库中.
我已经看到ActiveRecord有点像这样:
SomeModel.transaction do
# do stuff I did above
end
Run Code Online (Sandbox Code Playgroud)
这对Mongoid也有用吗?
谢谢你的帮助!!!.
归档时间: |
|
查看次数: |
1386 次 |
最近记录: |