dhruvaray / backbone-associations

Create object hierarchies with Backbone models; Respond to hierarchy changes using regular Backbone events.
http://dhruvaray.github.io/backbone-associations/
MIT License
492 stars 75 forks source link

Nested backbone model gets assigned parent collection #164

Open cstaikos opened 8 years ago

cstaikos commented 8 years ago

Hi there - here's my situation:

I have a collection of Model As. Model A has, among other things, a 1:1 relationship with Model B.

There are instances where Model B would be part of a collection, and other instances where it is simply a single nest model within a parent Model A.

As such, we are setting Model B's url differently if it's a part of a collection or not.

The strange thing is, when Model B is a child of a Model A, which is itself a part of a collection of Model As, if I check modalAInstance.get("modelB").collection, it is the collection of Model As.

Is this expected behavior? This Model B isn't actually part of a collection, so if I check it's collection it should be null I would think? For some reason though it seems to say "well, I'm a child of an instance of Model A, and that is in a collection, so that collection must be my collection!". This seems at least counter-intuitive, possibly a bug.

Let me know if this is unclear at all - thanks!