I'm trying to create a backbone relational model with 2 "hasMany" relations of the same type, but I'm getting the error: "Cannot create relation=child on "(myReverseRelationName)" for model=child: already taken by relation=child". Is this something that is supposed to be allowed, or am I doing it wrong? Thanks.
I've created a jsFiddle so you guys can take a look for yourselves: http://jsfiddle.net/Mu68f/5/
And here's the code:
Animal = Backbone.RelationalModel.extend({
urlRoot: '/animal/',
});
AnimalCollection = Backbone.Collection.extend({
model: Animal
});
Zoo = Backbone.RelationalModel.extend({
relations: [
{
type: Backbone.HasMany,
key: 'largeAnimals',
relatedModel: Animal,
collectionType: AnimalCollection,
reverseRelation: {
key: 'livesIn',
includeInJSON: false
}
},
{
type: Backbone.HasMany,
key: 'smallAnimals',
relatedModel: Animal,
collectionType: AnimalCollection,
reverseRelation: {
key: 'livesIn',
includeInJSON: false
}
},
]
});
// initialize our zoo
var zoo = new Zoo({
largeAnimals: [{name: "Big Bill"}],
smallAnimals: [{name: "Pee Wee"}]
});
console.log(zoo);