I want to be able to save a developer instance, and to automatically save all the associated languages at the same time.
Is there any clean way to do this with the current status of ember-data, or do I have to loop through all the languages and manually save them after saving the developer?
This could work. Unfortunately, invoke returns an array while I’d need a promise.
And I’d need to be able to transition the route, but only once all saves have been done.
var promises = new Array();
developer.save().then(function(developer) {
developer.get('languages').forEach(function(language) {
if(language.get('isDirty') {
promises.push(language.save());
}
});
}, function(error) {
//developer failed to save;
});
Ember.RSVP.all(promises).then(function() {
//transition here
}, function(error) {
//one or more languages failed to save
});
developer.save().then(function(developer) {
developer.get('languages').save().then(function() {
//transition here
}, function(error) {
//a language failed to save
});
}, function(error) {
//developer failed to save;
});
This appears to not work in EmberJS 2.7. It throws an error on getting the children:
TypeError: newTrail.get(...).save is not a function
newObject.save().then(function (newTrail) {
newTrail.get('assignments').save().then(function() {
console.log('DONE'); <-- eventually a transition here
});
});