1
我正在使用Rails 4.1.4和Mongoid在我的应用程序中。使用Mongoid在Rails中执行原子块事务
我只是想知道是否有在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
我想换行代码在单个原子事务,我的意思是,如果出现错误,我想无论这两种情况下的(some_model_instance,other_model_instance )被保存到数据库。
我已经看到了与ActiveRecord的在某种程度上是这样的:
SomeModel.transaction do
# do stuff I did above
end
这是否工作也Mongoid?
感谢您的任何帮助!
MongoDB没有交易,所以你必须自己做一个穴居人。 – 2014-10-03 17:16:21