Frage

If I update it as follows:

model = ModelClass.create(id: 1, foo: 'bar')
model.updateAttribute('id', '123')

I have 2 instances of this object:

// in chrome console
>ModelClass.records
Object {1: ModelClass, 123: ModelClass}

How can I update model id without duplication of models?

P.S. To synchronize with the server I'm using web sockets. I need to update the temporary id to the real

War es hilfreich?

Lösung

The id is a special attribute that should not be updated that way. Use model.changeID("someNewId"), which saves the new mapping. This function doesn't seem to be documented.

Spine's documentation is a bit behind its development, but check out the Model class here: https://github.com/spine/spine/blob/master/src/spine.coffee

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top