Skip to content

Commit

Permalink
Merge pull request #4279 from jgonggrijp/document-defaults-idAttribute
Browse files Browse the repository at this point in the history
Add warning to documentation about setting the model id in the defaults
  • Loading branch information
jgonggrijp committed Aug 10, 2023
2 parents c6c6dda + 97afbe8 commit 5df475d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.html
Expand Up @@ -1404,6 +1404,16 @@ <h2 id="Model">Backbone.Model</h2>
Instead, define <b>defaults</b> as a function.
</p>

<p class="warning">
If you set a value for the model&rsquo;s
<a href="#Model-idAttribute"><tt>idAttribute</tt></a>, you should define
the defaults as a function that returns a different, <u>universally</u>
unique id on every invocation. Not doing so would likely prevent an
instance of <tt>Backbone.Collection</tt> from correctly identifying model
hashes and is almost certainly a mistake, unless you never add instances
of the model class to a collection.
</p>

<p id="Model-toJSON">
<b class="header">toJSON</b><code>model.toJSON([options])</code>
<br />
Expand Down

0 comments on commit 5df475d

Please sign in to comment.