jeudi 14 avril 2016

Ember include id property in POST payload

I have the following models:

  1. A "generic" model reference used for listing values
  2. user model

Now, user can have many departments whose model is exactly reference.

How can I declare in user model that the departments can have many reference objects?

I tried the following but can't make it work:

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

export default DS.Model.extend({
    name: DS.attr('string'),
    departments: DS.hasMany('reference')
});

For what it's worth, this question stemmed from needing to include the id in the POST payload using Ember Data. My original user model is like this:

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

export default DS.Model.extend({
    name: DS.attr('string'),
    departments: DS.attr()
});

Problem with above model, whenever I save a record, it doesn't include the ID of the references in the payload even though they're already loaded in the store.

Do I need to create a custom serializer for the user model?

Aucun commentaire:

Enregistrer un commentaire