Ember data - find out if a record is saved on the server

I am running into a situation where I have an ember data record and I don’t know if it was already stored on the server or not. Is there a way to find out?

(Using ember-data (1.0.0-beta.11) and ember (1.8.0))

Before saving to the server, the ID will be something like 9gdh5

, so I just checked at first isNaN(+record.get('id'))

, but unfortunately this happens sometimes when the temporary ID generated by ember does not contain letters.

A search showed that the ember data was previously using the property _clientId

, but that seems to be gone. Am I missing something obvious or do I need to manually control a flag saying the entry came from a server or was created locally?

Here's some info on my use case, in case it helps clarify ...

My app works both offline and offline. My custom adapter knows when it is offline and sends LocalStorage requests to be sent online. The user can update records, and when the adapter receives this update, he needs to know if the record has been synced to the server. If so, it queues up a request PUT

to be sent to the server when accessed online. If the post has not been synced yet, we cannot complete the request PUT

because we do not know the post ID (which is part of the URL for PUT

). So instead, we have to find the locally saved query POST

and update it. So I want a reliable way to find out if a recording has been synced to the server or not ...

+3


source to share


1 answer


http://emberjs.com/api/data/classes/DS.Model.html#property_isNew



This may be new since this issue was created, but I came here looking for an answer, so I thought I'd paste what I found.

+2


source







All Articles