How to use multiple extensions in Backbone.Model.extend?

backbone.js, javascript, node.js

Solution

Just extend from both classes.

You can provide any object to `.extend`, not just an object literal. Extend your own class from `Deepmodel`, then extend a new class from `RelationalModel`, providing the `Deepmodel`-extended class's prototype:

var MyModel = Backbone.Deepmodel.extend({ ... })

MyModel = Backbone.RelationalModel.extend(MyModel.prototype);

Problem

I am working on a project that creates models in such a manner. ``` Backbone.DeepModel.extend({ ... }); ``` This deepmodel allows for deeply nested attributes to be refereed via sytax such as ``` containerGrid.get('cols')[0]['content'] ``` Now I have to implement nested models in a one-to-many format. Deep model doesn't support this, but a library called backbone-relational.js does. The syntax for this library is ``` Backbone.RelationalModel.extend({ ... }); ``` The functionality for these libraries does not overlap, and it is not possible for me to rewrite all of the code currently implemented with the Backbone.Deepmodel syntax. Is there another library I can use which supports both functionalities or another workaround you might recommend? Thank you very much for reading, I really appreciate your time and effort!

Original source