DS.ManyArray#createRecord
は createRecord
をもっていてそのままつくれる
DS.PromiseArray
はもってなくて作れないので、ManyArray
にしてあげてから作るのがベストの様子
ManyArray#createRecord
内部で owner
, store
, type
を用意してくれる
App.Post = DS.Model.extend({
comments: DS.hasMany('comment', {async: true})
});
App.Comment = DS.Model.extend({
post: DS.belongsTo('post')
});
App.CommentsController = Ember.ArrayController.extend({
actions: {
create: function(data){
this.get('model').then(function(comments){ // DS.PromiseArray
var comment;
comment = comments.createRecord(data); // DS.ManyArray
comment.save().then(function(comment){
// 成功
}, function(xhr){
// 失敗
});
});
}
}
});