Automatically generate id in ember data with local storage adapter

I need a way to generate an identifier for a new record added to the repository. I am using a local storage adapter . and look for some way and find features such as in the local storage adapter:

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

but the problem with this function is that this function creates identifiers in a string, I need an automatic increment id in an integer area. for example, 1 or 2 or 2000, and if a new record is added, the identifier has a maximum of identifiers in the record plus 1. I need to do this on the client side, and not on the server.

+4
source share
1 answer

If you want a "counter-type" id , you can always do what fixture_adapter does, which should have a variable called counter , and increment it every time (see here ).

But then, what happens if the record is deleted? Do you want to have another new record with the id of the old deleted record? And if instead you have some kind of global counter that ALWAYS increments by 1, which will take into account the problem that I mention, then in any case you just assign quite a few random identifiers, so why not go with the generating approach random identifiers, where did you start? :)

0
source

All Articles