I have two models (User and Task) that are instances of Backbone.RelationalModel
.
The relationship to these two models is as follows:
// Task model var Task = Backbone.RelationalModel.extend({ relations: [ { type: 'HasOne', key: 'user', relatedModel: User } ], urlRoot: 'someUrl' });
Then I have one collection whose code looks like this:
var FollowerCollection = Backbone.Collection.extend({ initialize: function () { _.bindAll(this); } model: User }); var User = Backbone.RelationalModel.extend({ });
When I make a selection on a FollowerCollection, I get the following error:
Uncaught TypeError: Cannot read property 'idAttribute' of undefined
on line 1565 of the underlying relationship. js backbone-relation version 0.5.0
Here's the code snippet backbone-relation.js
if ( !( model instanceof Backbone.Model ) ) { // Try to find 'model' in Backbone.store. If it already exists, set the new properties on it. var existingModel = Backbone.Relational.store.find( this.model, model[ this.model.prototype.idAttribute ] );
The problem is with _.bindAll(this)
, because if I comment on it, it works correctly.
What for? Any ideas?
source share