Update model ID with ID from server response after save()


We have the following use case:

Our app should work when offline. New records should be stored transparently, and each record should be assigned a UUID String as ID. Once the client regains network connectivity, it should execute all the scheduled actions. This seems to be covered by Ember Sync.

However, I would like to retain integer IDs on the server side (Postgres performs better with those). This means that a record would have to be assigned another integer ID when it has been saved (POST) to the server. Some Stackoverflow thread seems to indicate that this worked in November, but today I get this error after the POST:

An adapter cannot assign a new id to a record that already has an id. ...

I tried to override the main store to nullify the record’s ID in didSaveRecord():

MainStore = DS.Store.extend(
  didSaveRecord: (record, data) ->
    if data?.id? and record?.id?
      record.set('id', null)

    @_super(record, data)

`export default MainStore`

Which kind of works, but the record subsequently loses its related objects. Not an option!

I am aware that this is a severe case of fighting the framework, and the hack above is only a desperate try; however I think that this use case is valid. Do you know of a way to have client-side UUIDs and incremental server-side IDs at the same time?


@manmal I’m currently in exactly the same situation. Did you find a solution yet or are you taking a different approach?


@DavidPhilip Sadly, no real solution, but we gave in instead: We now use UUIDs everywhere. They are easier to deal with in Rails 4, with some real downsides though (no .first and .last out of the box, queries use more memory in Postgresql).