简体   繁体   中英

Ember data : createObject with an initial async relationship value

I've been using ember and ember data for a few months and I am now working on optimisations of my webapp.

I have this feed model :

export default DS.Model.extend({
  app: DS.belongsTo('app', {async:true}),
  icon: DS.attr('string'),
  title: DS.attr('string'),
  typeName: DS.attr('string'),
  rootElement: DS.belongsTo('element', {async:true}),
  position: DS.attr('number'),
  fontAwesomeIcon:DS.attr('string'),

  htmlId:function () {
    return "module_"+this.get('id');
  }.property(),
});

When I am trying to create a new feed object I only need to specify my backend an app and a type so I do this :

addFeed: function() {
    var app=this.get('model');
    var selectTypeForm = document.getElementById('selectFeedType');
    var type = selectTypeForm.options[selectTypeForm.selectedIndex].value
    var newFeed = this.store.createRecord('feed', {
        app:this.get('model'),
        typeName:
    });          
    newFeed.save();
},

My problem is that if the app property is async (like in this example) the app id is never sent to my backend on the POST request (it's like I never set it). If I switch it to async:false in the feed model, it accepts my app id at creation and correctly sends it to my backend.

Is it impossible to write an async property ?

Thanks

Versions : Ember 1.7.0 and Ember data 1.0.0-beta.10

Ember Data had that bug for quite a long time, but it was fixed in Ember data 1.0.0-beta.11 for creation. Setting an async property was fixed in beta.12. Your easiest route is to upgrade.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM