ruby-on-railsrubyember.jstrailblazerember-engines

Update existing model data


Briefly something about our structure. We use Ruby on Rails on the server side with the Trailblazer Framework. On client side Ember and 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. 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. 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.

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. 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"}}}

Solution

  • 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