jashkenas/backbone — pull request #2923 by TrevorBurnham (2013-12-16 19:52:22+00:00)
Title: Add getBy method to return model based on an indexed attribute lookup

Currently, using an attribute other than the `idAttribute` for fast lookups within a collection is difficult, and using user-generated strings for the `idAttribute` is problematic (see #2920, #2922). I believe this is a common use case that merits support in Backbone core (see #1600, #2213). This PR adds such support through a new collection-level `indexedAttributes` property and a `getBy` method, used like so:

var IndexedCollection = Backbone.Collection.extend({
indexedAttributes: ['name']
});
var coll = new IndexedCollection([{name: 'Alice'}]);
coll.getBy('name', 'Alice');