通过使用Backbone-relational我希望以这种方式执行模型任务:
task = {
id: 1
assigned_id: 2
name: 'read a book',
user: userModel
};
我确实尝试过这种方式(1),但结果如下(2)。
有任何想法吗?
(1)
var User = Backbone.RelationalModel.extend({
// urlRoot
});
var Task = Backbone.RelationalModel.extend({
relations: [
{
type: Backbone.HasOne,
key: 'user',
relatedModel: User
}
],
// urlRoot
});
(2)
task = {
id: 1
assigned_id: 2
name: 'read a book',
user: null // null instead of having something related to user model
};