Skip to content

Instantly share code, notes, and snippets.

@richsoni
Created July 23, 2013 13:22
Show Gist options
  • Save richsoni/6062315 to your computer and use it in GitHub Desktop.
Save richsoni/6062315 to your computer and use it in GitHub Desktop.
Tutorial on how to use Base collection for Backbone

Creating Collections becomes much easier with the Base Collection.

In this example I will walk through some of the default conventions and requirements for creating such a collection.

to create a base extended collection, just extend base
(function (Collections) {
Collections.EmailAddresses = Collections.Base.extend({
model: Application.Models.Email,
});
})(Application.Collections);
#base collections get the validate method, which will validate each of the models
validate: -> @each (model) -> model.validate?()
#if a collection is within a nested model this means that it will return the validation errors of each of its own models when
#validate is called on the collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment