From df7a6f20337b159c81a05883e6f85661007b74a8 Mon Sep 17 00:00:00 2001 From: Harrison Shoff Date: Fri, 8 Mar 2013 16:27:54 -0800 Subject: [PATCH] add documentation about collections containing polymorphic models. Fixes #2338 --- index.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index.html b/index.html index b8a399ae..303d57c4 100644 --- a/index.html +++ b/index.html @@ -1493,6 +1493,25 @@ bill.set({name : "Bill Jones"}); var Library = Backbone.Collection.extend({ model: Book }); + + +

+ A collection can also contain polymorphic models by overriding this property + with a function that returns a model. +

+ +
+var Library = Backbone.Collection.extend({
+
+  model: function(attrs, options) {
+    if (condition) {
+      return new PublicDocument(attrs, options);
+    } else {
+      return new PrivateDocument(attrs, options);
+    }
+  }
+
+});