I have an app that keeps multiple task lists. Each task list has multiple tasks. Each task has multiple comments.
After updating to the new Ember Data, I had to scrap my record creation code. Currently I have this, which doesn't work. Though it doesn't throw any errors, my model does not seem to be updating.
App.TaskController = Ember.ArrayController.extend({
needs : ['list'],
isEditing : false,
actions : {
addTask : function(){
var foo = this.store.createRecord('task', {
description : '',
list : this.get('content.id'),
comments : []
});
foo.save();
console.log('Task Created!');
},
edit : function(){
this.set('isEditing', true);
},
doneEditing : function(){
this.set('isEditing', false);
}
}
});
Does anyone know how to create a new task (as well as how to create new comments) in this context?
See fiddle here : http://jsfiddle.net/edchao/W6QWj/
Okay, so I've answered my own question. I was missing the pushObject() method. Here is another way to do things. Although I'm not sure if it's the best practice since it does throw the error "Assertion failed: You can only add a 'list' record to this relationship "
Yes you need pushObject in the list controller.
I would do the addTask like this, now almost every method in ember data return a promise
I think seerting id's properly is very important, here with fixtures I do with a find, but with the rest adapter would be the backend who assign the id and set it in the response
JSFiddle http://jsfiddle.net/W6QWj/2/