Search code examples
collectionsmodelsbackbone.js

backbone.js: How can I access the parent model of a nested collection?


I have a model, let's call it "modelA", which has a nested "collectionX" of say "modelB".

  • modelA
    • collectionX (modelB)

When working with a modelB instance, I can easily access its siblings or its collection's meta data using this.collection.

How can I access attributes of the parent model (modelA)?


Solution

  • There is no default way to do this is backbone. Just add the modelA attribute to the collection and access it within modelB.