Reputation: 10044
In the Backbone.js docs it says that when you encounter circular reference you should redesign your app. I've been thinking about this for months (and working around it), but it keeps chasing me. Please look at my structure and tell me how you would design this.
It's quite simple, I have groups and I have people. Groups have people (members). A group can have a relation to groups (eg: an organization has departments) and people can have a relation to people (colleagues, manager, etc).
If I make all different models for groups and people (eg: organization, department, colleague, manager, etc) than there is no problem. But when I use inheritance (org extends group, dep extends group, colleague extends person, etc), circular reference kicks in.
How to solve this? A frequently heard answer is: use backbone-relational. It's probably fantastic software, but I want to understand how it works (more than get it to work ;) and thus want to do it myself.
Upvotes: 1
Views: 235
Reputation: 10044
The circular reference problem was (duh) RequireJS and not Backbone.
I kept running into this problem for a while. The RequireJS website says if you encounter circular reference than your design is not OK.
I redesigned. I now use two different models: a full one (with relations) that extends a minimal one (without the relations). The minimal one is used in the collection so the circular reference won't happen.
That's my solution so far. Any better ideas? :)
Upvotes: 1