2012-11-01 111 views
0

我试图使用Rails,CouchRest更新对象集合中的参数。使用CouchRest更新对象数组,Rails

这是即时通讯做目前,

class User 
    property :country 
    property :some_flag 
end 

@users = User.by_country(:key => 'country-name') 
@users.each do |user| 
    user.update_attributes({:some_flag => 'true'}) 
end 

每当update_attributes方法失败User对象,我想整个事务回滚。我怎样才能做到这一点?

正在使用CouchDB。 Rails,CouchRest和不是使用ActiveRecord。

回答

0

CouchDB中没有明确支持事务,但有一些所谓的“批量更新”,这可能会有所帮助:

http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API#Modify_Multiple_Documents_With_a_Single_Request

实例数据的更新:

{ 
    "all_or_nothing": true, 
    "docs": [ 
    {"_id": "0", "_rev": "1-62657917", "integer": 10, "string": "10"}, 
    {"_id": "1", "_rev": "2-1579510027", "integer": 2, "string": "2"}, 
    {"_id": "2", "_rev": "2-3978456339", "integer": 3, "string": "3"} 
    ] 
}