Merge pull request #2350 from hshoff/polymorphic

add documentation about collections containing polymorphic models. Fixes...
This commit is contained in:
brad dunbar
2013-03-08 16:46:06 -08:00

View File

@@ -1493,6 +1493,25 @@ bill.set({name : "Bill Jones"});
var Library = Backbone.Collection.extend({
model: Book
});
</pre>
<p>
A collection can also contain polymorphic models by overriding this property
with a function that returns a model.
</p>
<pre>
var Library = Backbone.Collection.extend({
model: function(attrs, options) {
if (condition) {
return new PublicDocument(attrs, options);
} else {
return new PrivateDocument(attrs, options);
}
}
});
</pre>
<p id="Collection-constructor">