Ember Localstorage adapter generated ID's


#1

I’m using the localstorage adapter and have no web service. It is possible to have my ID’s ordered numerically when I create new records? i.e (0, 1, 2, 3, 4, 5) vs (ard79, j12jk, kjals9, aa2ji2)


#2

You could extend the adapter and override the ID generator:

generateIdForRecord: function () {
  return Math.random().toString(32).slice(2).substr(0, 5);
},

You’d surely have to add some magic to track the highest assigned ID and such, though.


#3

I’m using Ember.uuid(), which generates incrementing integers (not real UUID’s per se). I set the id and a clientId on new records, and the server response will contain a server-generated UUID along with the clientId so the record can be updated.