jeudi 9 novembre 2017

Ember.js: saving a relationships destroy belongsTo relationships

I have a model, lets call it house, and an other, kitchen. When I try to save the house model, its relationships belongsTo() to kitchen is destroyed.

house has a belongsTo() relationships to kitchen, like that:

export default DS.Model.extend(DeviceValidation, {
    name: DS.attr('string'),
    kitchen: DS.belongsTo('kitchen', {polymorphic:true}),
});

kitchen is a very simple model:

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

I am creating my record, filling it and finally saving it in a component. This is the function associated to it.

 createHouse() {
    this.createKitchen().then(() => { // this will create, fill and save a kitchen record
          this.createAnSetHouse(); // this will create and fill a house record as 'house'
          console.log(this.get('house').get('kitchen')); // this properly get the kitchen record
          this.get('house').save().then(() => {
              console.log(this.get('house').get('kitchen')); // and here the relationships is set to null ???
          / * rest of the function * / 
    }

As you can see in the snippets above, once, I save the jhouse record, the relationships is set to null, even if it was properly set beforehand.

Any tips is appreciated.




Aucun commentaire:

Enregistrer un commentaire