mardi 17 avril 2018

Cannot call save a on an ember-data relation

I want to handle a relation in a component/form. It works fine when I create the relation, but it fails when I try to update

import Ember from 'ember';

export default Ember.Component.extend({
  store: Ember.inject.service(),
  init(){
    this._super(...arguments);
    var adresseField=this.get('adresseAttributeField');
    var parent=this.get('parent');
    if (parent.get(adresseField).content==null) {
      this.set('adresse',this.get('store').createRecord('adresse'));
    }else{
      this.set('adresse',parent.get(adresseField));
    }
  },
  actions:{
    saveAdresse(adresse){
      console.log(adresse);
      var parent=this.get('parent');
      var adresseField=this.get('adresseAttributeField');
      adresse.save().then(()=>{
        if(parent.get(adresseField)!=adresse){
          parent.set(adresseField,adresse)
          parent.save()
        }
      }),()=>{
      }
    }
  }
});

I think my problem is in the init when I retrieve the existing relation :

this.set('adresse',parent.get(adresseField));

However I cannot identify what's the problem exactly.




Aucun commentaire:

Enregistrer un commentaire