Mostly in any application, we may need to have models that are related to each other. For example, a blog post model can have a relationship with a model of its author or have a connection to a comment model.
We may also need to access comments quickly when dealing with a blog post, or list all blog posts of a specific author. Moreover, we may want to export blog posts with author info and comments in a single JSON format.
In a Backbone app, this can be implemented with the help of the Backbone-relational
extension.
You can download the Backbone-relational
extension from the GitHub page https://github.com/PaulUithol/Backbone-relational. To include Backbone-relational
into your project, save the backbone-relational.js
file into the lib
folder and include a reference to it in index.html
.
Note
Including a Backbone extension into your project is described in the Extending application with plugins recipe in Chapter 1, Understanding Backbone in detail...