简体   繁体   English

在Ember-data中以自定义方式保存属性

[英]Save an attribute in a custom way in Ember-data

Say that I have a model, which has some attributes which are stored in a database, and another one which is stored some place else, but the client receives it as a one single JSON blob. 假设我有一个模型,它有一些存储在数据库中的属性,另一个存储在其他地方,但是客户端将它作为单个JSON blob接收。

App.Tournament = DS.Model.extend({
  name:              DS.attr("string"),
  ...
  is_registered:     DS.attr("boolean")
});

the attribut is_registered is not a part of the model in the server, and I would like to save it separately. attribut is_registered不是服务器中模型的一部分,我想单独保存它。 Here's an example 这是一个例子

tournament = App.store.find(App.Tournament, 1);
tournament.set("name", "foo bar");
tournament.set("is_registered", true);

App.store.commit();

and this would do something like 这会做类似的事情

PUT /tournaments/1 name: "foo bar"
POST /tournaments/1/register

or something like that, where an attribute is saved different than the default. 或类似的东西,其中保存的属性不同于默认值。 Is there a simple way to do this, or am I approaching the problem in a wrong way? 有一种简单的方法可以做到这一点,还是我以错误的方式处理问题?

I would manage this complexity on the server. 我会在服务器上管理这种复杂性。 The problem with saving one logical item on the client in more than 1 request is that if one of the requests failed, your data might be corrupted. 在多个请求中在客户端上保存一个逻辑项的问题是,如果其中一个请求失败,则您的数据可能已损坏。 If you do some sort of Facade service that coordinates what data goes where, you can wrap a transaction around the operation. 如果您执行某种Facade服务来协调哪些数据在哪里,您可以围绕操作包装事务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM