Skip to content

Commit

Permalink
jashkenas#819 documenting idAttribute. Also requested on pull req jas…
Browse files Browse the repository at this point in the history
  • Loading branch information
Irene Ros committed Dec 26, 2011
1 parent 4226d58 commit 5701569
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions index.html
Expand Up @@ -684,7 +684,30 @@ <h2 id="Model">Backbone.Model</h2>
Models can be retrieved by id from collections, and the id is used to generate
model URLs by default.
</p>

<p id="Model-idAttribute">
<b class="header">idAttribute</b><code>model.idAttribute</code>
<br />
By default a model assumes its unique identifier is stored
under the <b>id</b> attribute.
In certain situations, for example when using CouchDB where the
identifying attribute is called <b>_id</b>, overwriting the property
name is necessary.
Setting the <b>idAttribute</b> during a model definition will
set the model's <b>id</b> to the value of the idAttribute property
instead. When referencing the model's <b>id</b>, continue
using <b>model.id</b>.

<pre class="runnable">
var Meal = Backbone.Model.extend({
idAttribute: "_id"
});

var cake = new Meal({ _id: 1, name: "Cake" });
alert("Cake id: " + cake.id);
</pre>
</p>

<p id="Model-cid">
<b class="header">cid</b><code>model.cid</code>
<br />
Expand Down

0 comments on commit 5701569

Please sign in to comment.