简体   繁体   English

更新现有模型数据

[英]Update existing model data

Briefly something about our structure. 简要介绍一下我们的结构。 We use Ruby on Rails on the server side with the Trailblazer Framework. 我们在服务器端使用Trailblazer框架使用Ruby on Rails。 On client side Ember and Ember Engines. 在客户端Ember和Ember Engines。

Now we have the problem that some models are lying in the father, ie the actual Ember app and some models in the engine. 现在,我们面临的问题是某些模型位于父级,即实际的Ember应用程序和引擎中的某些模型。 Now the models from the engine still have relations to models which are in the father app. 现在,引擎中的模型仍然与父应用程序中的模型有关系。 If I now want to update data from this model, the engine model works very well, with the relations (which are in the father) he always makes an INSERT and no UPDATE. 如果现在我想从该模型中更新数据,则引擎模型可以很好地工作,并且具有关系(在父关系中),他总是进行INSERT而不进行UPDATE。 There is, of course, an error that the entry already exists. 当然,该条目已经存在一个错误。

ActiveRecord::RecordNotUnique - PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "contacts_pkey" DETAIL: Key (id)=(1) already exists. ActiveRecord :: RecordNotUnique-PG :: UniqueViolation:错误:重复的键值违反了唯一约束“ contacts_pkey”详细信息:键(id)=(1)已存在。

Anyone have an idea how to solve the problem and update the engine model and father model? 有人知道如何解决问题并更新引擎模型和父模型吗? In the Ember Store, everything is correctly linked and the data is also distributed correctly into the relations. 在Ember Store中,所有内容均正确链接,数据也正确分配到关系中。 On the server comes the following: 在服务器上有以下内容:

Parameters: {"data"=>{"attributes"=>{"patient-number"=>1, "email"=>nil, "employer"=>"", "foreign-doctor"=>"", "family-doctor"=>"", "patient-since"=>"2017-08-02T00:00:00.000Z", "job"=>"", "lab"=>"", "last-therapy"=>"2017-08-02T00:00:00.000Z", "payment-deadline"=>28, "rating"=>1, "recall-type"=>nil, "recommended-by"=>"", "phrophylaxis-user"=>nil, "created-at"=>nil, "updated-at"=>nil, "contact-id"=>nil, "import-id"=>nil}, "relationships"=>{"contact"=>{"data"=>{"type"=>"contacts", "id"=>"1"}}, "customer"=>{"data"=>{"type"=>"customers", "id"=>"1"}}, "patient-insurances"=>{"data"=>[]}, "users"=>{"data"=>[{"type"=>"users", "id"=>"1"}]}, "person"=>{"data"=>{"type"=>"people", "id"=>"1"}}}, "type"=>"patients"}, "id"=>"1", "patient"=>{"data"=>{"attributes"=>{"patient-number"=>1, "email"=>nil, "created-at"=>nil, "updated-at"=>nil}, "relationships"=>{"contact"=>{"data"=>{"type"=>"contacts", "id"=>"1"}}, "person"=>{"data"=>{"type"=>"people", "id"=>"1"}}}, "type"=>"patients"}}}

I found the Solution. 我找到了解决方案。 In the Operation was this missing: 行动中缺少以下内容:

public def set_MODELNAME(options, **)
    MODELNAME = [MODELNAME].find(options['contract.default'].MODELNAME.id)
    options['contract.default'].MODELNAME = MODELNAME
end

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

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