jeudi 15 septembre 2016

EmberJS 2.7 = has_many configuration for Ember-Data and Active Model Serializers with embedded IDs and sideloading

This is a similar question to this one, except this is for the latest versions of Ember and Active Model Serializers (0.10.2).

I have a simple Parent:Child relationship.

app/models/trail.js

import Ember from 'ember';
import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr(),

  // relationships
  employees: DS.hasMany('employee', { async: true }),

});

When I create a new Trail, and select two employees for the 'hasMany', the following json is sent to the server

 {"data"=>{"attributes"=>{"name"=>"TEST3", "gpx-file-url"=>"a url", "distance-value"=>5}, "relationships"=>{"employees"=>{"data"=>[]}}, "type"=>"trails"}}

My question is, what has happened to the employees? Where are the id's of the employees I selected (they already exist both in the database and in the Ember Store). I can see these employees when I view the record in Ember, but if I refresh the page of course they are now gone.

Using JSONAPI, AMS and NOT embedding the data using the EmbeddedRecordsMixin. Surely this is the latest and greatest way of doing things, where the employees will be sideloaded when they come back from the server? But if I cannot send the id's in the first place .... argh!




Aucun commentaire:

Enregistrer un commentaire