Description: reverseRelation Collection is always instanceof Backbone.Collection
Expected: reverseRelation Collection is instanceof Routes
Actual: reverseRelation Collection is instanceof Backbone.Collection only
How to reproduce:
jsFiddle example: http://jsfiddle.net/mauron85/8uhvyq9L/
var User = Backbone.RelationalModel.extend({
defaults: {
routes: []
}
});
var Route = Backbone.RelationalModel.extend({
relations:[{
type: Backbone.HasOne,
key: 'user',
relatedModel: User,
includeInJSON: 'id', //serialize only id not a full object
reverseRelation: {
key: 'routes',
includeInJSON: 'id'
}
}]
});
var Users = Backbone.Collection.extend({
model: User,
url: '/users'
});
var Routes = Backbone.Collection.extend({
model: Route,
url: '/routes',
someMethod: function () {
console.log('you just called some method');
}
});
var userJSON = [{
id: 'john'
},{
id: 'pete'
}];
var routesJSON = [{
id: 'first',
user: 'pete'
},{
id: 'second',
user: 'john'
}];
var users = new Users(userJSON);
var routes = new Routes(routesJSON);
var johnRoutes = users.at(0).get('routes')
console.log(johnRoutes.at(0).get('id') === 'second'); // TRUE
console.log(johnRoutes instanceof Backbone.Collection); // TRUE,
console.log(johnRoutes instanceof Routes); // FALSE, we cannot call Routes methods!!!
johnRoutes.someMethod(); // Uncaught TypeError: johnRoutes.someMethod is not a function
Modified version with model collection as constructor option throws:
Uncaught TypeError: collection.on is not a function
jsFiddle: http://jsfiddle.net/mauron85/8uhvyq9L/4/
Description: reverseRelation Collection is always instanceof Backbone.Collection
Expected: reverseRelation Collection is instanceof Routes
Actual: reverseRelation Collection is instanceof Backbone.Collection only
How to reproduce:
jsFiddle example: http://jsfiddle.net/mauron85/8uhvyq9L/
Modified version with model collection as constructor option throws:Uncaught TypeError: collection.on is not a functionjsFiddle: http://jsfiddle.net/mauron85/8uhvyq9L/4/