我正在尝试实施 BackboneRelational 并不断获得
“每个类型不能实例化多个具有相同 id 的 Backbone.RelationalModel!”
class App.Models.User extends Backbone.RelationalModel
urlRoot : '/api/users'
idAttribute: 'id'
relations: [
type: Backbone.HasMany
key: 'plots'
relatedModel: 'App.Models.Plot'
collectionType: 'App.Collections.Plots'
includeInJSON: false
reverseRelation:
key: 'user_id',
includeInJSON: 'id'
]
class App.Models.Plot extends Backbone.RelationalModel
urlRoot : '/api/plots'
idAttribute: 'id'
如果我将其中一个模型切换为 extends Backbone.Model 我可以实例化两者,但我会收到所有有关关系功能已损坏的警告。
我正在努力实现以下目标:
plot = new App.Models.Plot({id : 700})
plot.fetch()
plot.get('user')
我错过了什么?