使用hasMany associacion持久保存新模型实体的任何示例?
答案 0 :(得分:2)
以下是一个示例,请参阅http://jsfiddle.net/pangratz666/vuT2v/
App.Comment = DS.Model.extend({
text: DS.attr('string')
});
App.Post = DS.Model.extend({
title: DS.attr('string'),
comments: DS.hasMany('App.Comment')
});
var first = App.Comment.createRecord({
id: 'firstComment',
text: 'first comment'
});
var second = App.Comment.createRecord({
id: 'secondComment',
text: 'second comment'
});
var post = App.Post.createRecord({
id: 1,
title: 'post title'
});
var comments = post.get('comments');
comments.addObject(first);
comments.addObject(second);
App.store.commit();