PaulUithol/Backbone-relational — Issue #54: Endless recursion for back references
Author: ginkel
Created: 2011-12-09 00:18:29+00:00
State: open

I have two models that both reference each other:

```
class App.Models.B extends Backbone.RelationalModel
relation: [{
type: Backbone.HasOne,
key: 'a',
relatedModel: 'A',
reverseRelation: {
key: 'bs',
includeInJSON: 'id'
}
}]

class App.Models.A extends Backbone.RelationalModel
relation: [{
type: Backbone.HasMany,
key: 'cs',
relatedModel: 'C',
collectionType: 'CsCollection',
reverseRelation: {
key: 'a',
includeInJSON: 'id'
}
}, {
type: Backbone.HasMany,
key: 'bs',
relatedModel: 'B',
collectionType: 'BsCollection',
reverseRelation: {
key: 'a',
inclideInJSON: 'id'
}
}
]
```

Unfortunately, when saving an instance of B, Backbone-relational aborts with a stack overflow error after unlocking the event queue:

Uncaught RangeError: Maximum call stack size exceeded
Backbone.Collection.trigger
_.extend._onModelEvent
Backbone.Events.trigger
Backbone.RelationalModel.Backbone.Model.extend.trigger
_.extend.add
Backbone.RelationalModel.Backbone.Model.extend.trigger
_.extend._onModelEvent
Backbone.Events.trigger
Backbone.RelationalModel.Backbone.Model.extend.trigger
_.extend.add
Backbone.RelationalModel.Backbone.Model.extend.trigger
_.extend._onModelEvent
...

Any ideas what I may be doing wrong?