mardi 15 octobre 2019

How to create a record in ember.js while throwing a required data to it's relationship?

Please help me. I have a two model which are foo and bar models. I was trying to create a record on /foos endpoint using the POST /foos. However the post POST /foos has a requirement of relationships.bar.data.id=1,2,3. Please see my code below for /components/foo-bar.js. My question is how to create a foo record and declaring those ids to it's relationship?

/components/foo-bar.js

  foo.setProperties({
    bar: [1213,1231]
  });


 /models/foo.js
 import DS from 'ember-data';

  export default DS.Model.extend({
    bar:  DS.belongsTo('bar', { async: true }),
  });

  /models/bar.js
  import DS from 'ember-data';

  export default DS.Model.extend({
    foos:  DS.hasMany('foo', { async: true }),
  });



Aucun commentaire:

Enregistrer un commentaire