maccman/spine — pull request #320 by doublerebel (2012-06-04 19:07:22+00:00)
Title: Make it possible to overwrite client id prefix; also enables catching duplicate ids & cids

Currently, uid can never detect id or cid collisions because it has no idea of the prefix set for cid.

I believe because uid is only called in one place, the prefix should be set at uid. Then uid can be overridden to provide a custom prefix and also to detect collisions. Therefore it will be a truly "unique id".

I discovered this problem when extending the model to use local storage.

For example:

Using Spine.Model.Local
say Local has ids c-1
fetch() then will end up assigning id c-1 -> cid c-0

Then in create...

...create new id, will have cid c-1, which is then set as id...
@id = @cid unless @id

...and then overwrites the old record...
@constructor.records[@id] = record
@constructor.crecords[@cid] = record

...this is further finalized when saving.