Skip to content

Instantly share code, notes, and snippets.

@Microfed
Last active December 23, 2015 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Microfed/6573839 to your computer and use it in GitHub Desktop.
Save Microfed/6573839 to your computer and use it in GitHub Desktop.
Ember-data has many async problem
// 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?
@ryanirilli
Copy link

I am also having this issue. any solution yet?

@benmoss
Copy link

benmoss commented Nov 25, 2013

me too! the only google hit for that exception!

@courthead
Copy link

The code at the bottom of the OP's example works fine for me:

modelInstance.get('field').then(function(field) {
  field.pushObject(otherModelInstance);
});

Calling modelInstance.get('field') instantly resolves the promise.

@claptimes5
Copy link

Thanks @courthead. Worked for me as well.

@Manumie
Copy link

Manumie commented Jan 30, 2014

Thanks @courthead.

@aBuder
Copy link

aBuder commented Feb 6, 2014

@courthead

Thanks thats the solution

@e00dan
Copy link

e00dan commented Mar 23, 2014

@courthead
Solved my issue for this project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment