In the last chapter, Models and Domain Logic, we learned that Models provide a powerful infrastructure for domain logic, server interactions, and events. In this chapter, we will see how Collections expand upon these capabilities, letting us manage similar Models together as a group. The convenience provided by Collections is staggering. In addition to making your life much easier, Collections are well equipped in their role as a part of your domain model. They are the proper home for elements of domain logic that apply not to a single Model, but rather to a group of Models of the same type. In the fundamental Backbone divide between Models and Views, Collections are firmly on the side of Models.

The bulk of this chapter is concerned with what we can broadly categorize as domain logic, including membership, queries, and bulk operations such as sorting. Then, we will quickly cover events and interactions with a persistent data store. To better understand how data store interactions work, we will also look at Backbone.sync, the function that provides the Ajax code used by Models and Collections.


The rest of this chapter is part of the interactive book Backbone + CoffeeScript.