I'm trying to learn more about creating custom adapters in Ember so I started one where I want to create and update records in sessionStorage. I have the createRecord method working, but in the updateRecord method, the id is always null. Any idea why? For the id of models, I am just using a timestamp.
export default DS.Adapter.extend({
createRecord(store, type, snapshot) {
var data = this.serialize(snapshot, { includeId: true });
return new Ember.RSVP.Promise((resolve, reject) => {
var comments = {}, id = Date.now();
if (window.sessionStorage.getItem('comment')) {
comments = JSON.parse(window.sessionStorage.getItem('comment'));
}
data.id = id;
comments[id] = data;
window.sessionStorage.setItem('comment', JSON.stringify(comments));
resolve(data);
});
},
updateRecord(store, type, snapshot) {
var data = this.serialize(snapshot, { includeId: true });
var id = snapshot.id;
console.log('updating', id); // id is null. Why???
return new Ember.RSVP.Promise((resolve, reject) => {
resolve(data);
});
}
});
I am aware that I need to create a few other methods like findAll(), findRecord() etc, but would not having those cause this issue? I'm not sure what I am missing. Thanks in advance!