Ember.js Data Conflict Resolution / Failing on Conflict

If using Ember.js with the ember-data REST adapter, is there some sort of conflict resolution strategy for handling persisting data to the server?

At the very least, for my case, failing and rolling back would be sufficient in the case of conflicts, if the user can be informed of this. So, would sort of data/structure would be required for this? Some sort of "version" id on the models, where the server can check the submitted versions, and make sure that the client had the most recent data. Is there anything in Ember.js to make this a bit less manual? And if so, what?

Edit: Also, is there anything that helps with conflicts of bulk commits of models? Say we have a parent model with a "hasMany" relationship to several child models, and all of them are to be persisted to the database at the same time. If just dealing with server-side code, I feel I could wrap this up on a transaction in whatever database I'm using, and fail if something is out of date. How does this translate to Ember.js transactions?

I see a flag bulkCommit in the Adapter class. This seems to be able to bulk commit objects of the same type, in one request. However, if I'm persisting records of more than one type, then this would result in multiple requests to the server. Is there a way to either a) make this happen in one request to the server, or b) match up ember-data's transactions with transactions on the server, so if the transaction on the server fails, and needs to be rolled back, the ember-data transaction fails as well?

[I'm evaluating Ember.js for an upcoming project, and testing a few features and what it's like to develop in. I'm actually considering more real-time updates using socket.io or similar. I see derby.js has made some movements towards automatic conflict resolution]


As you can see in the Ember Data source code here, you can return 422 HTTP status code with errors as dictionary. Errors will be added to the model by Ember Data library by key as model's property and the model itself will be considered invalid . Model will automatically leave this state once each property with errors on them changed.

You could watch for errors on version property and reloadRecord once concurrency error appears.

链接地址: http://www.djcxy.com/p/65578.html

上一篇: 查找belongsTo关系的值

下一篇: Ember.js数据冲突解决/冲突失败