Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a Backbone model id need to be numeric?

Tags:

backbone.js

As the question asks, is it necessary to have a numeric (and presumably, integer) value for a model's id? Or is any unique identifier acceptable? For example, could I use a GUID string?

like image 729
T Nguyen Avatar asked Oct 10 '13 20:10

T Nguyen


1 Answers

It can be any arbitrary string according to the docs:

ID

A special property of models, the id is an arbitrary string (integer id or UUID). If you set the id in the attributes hash, it will be copied onto the model as a direct property. Models can be retrieved by id from collections, and the id is used to generate model URLs by default.

like image 124
Nick Tomlin Avatar answered Dec 08 '22 05:12

Nick Tomlin