Last active
December 23, 2015 03:29
-
-
Save Microfed/6573839 to your computer and use it in GitHub Desktop.
Ember-data has many async problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I found a strange problem: | |
// if model describes like that: | |
App.otherModel = DS.Model.extend({ | |
text: DS.attr('string') | |
}); | |
App.model = DS.Model.extend({ | |
field: DS.hasMany('otherModel', {async: true}) | |
}); | |
// and model.field is empty, | |
// then adding a new element to the field | |
var modelInstance = store.createRecord('model'), // store is defined | |
otherModelInstance = store.createRecord('otherModel'), | |
modelInstance.get('field').pushObject(otherModelInstance) | |
// causes an error: 'The content property of DS.Promise Array should be set before modifying it' | |
// and adding an object in another way: | |
modelInstance.get('field') | |
.then(function (field) { | |
field.pushObject(otherModelInstance); | |
}); | |
// wouldn't work because the promise will not actually resolved. | |
// How can we add objects to model.field in that case? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@courthead
Thanks thats the solution