From 570156914d540177e35967f36e3e934e0fbec944 Mon Sep 17 00:00:00 2001 From: Irene Ros Date: Mon, 26 Dec 2011 15:00:02 -0500 Subject: [PATCH] #819 documenting idAttribute. Also requested on pull req #210. --- index.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/index.html b/index.html index c9d5f29a4..d25868b8f 100644 --- a/index.html +++ b/index.html @@ -684,7 +684,30 @@

Backbone.Model

Models can be retrieved by id from collections, and the id is used to generate model URLs by default.

+ +

+ idAttributemodel.idAttribute +
+ By default a model assumes its unique identifier is stored + under the id attribute. + In certain situations, for example when using CouchDB where the + identifying attribute is called _id, overwriting the property + name is necessary. + Setting the idAttribute during a model definition will + set the model's id to the value of the idAttribute property + instead. When referencing the model's id, continue + using model.id. + +

+var Meal = Backbone.Model.extend({
+  idAttribute: "_id"
+});
 
+var cake = new Meal({ _id: 1, name: "Cake" });
+alert("Cake id: " + cake.id);
+
+

+

cidmodel.cid