Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save visualjeff/3d7d06be88d777153f61228d29c106d9 to your computer and use it in GitHub Desktop.
Save visualjeff/3d7d06be88d777153f61228d29c106d9 to your computer and use it in GitHub Desktop.
ember-data override to rev attributes when null. data source (couchdb) doesn't want a null rev attribute when adding (POSTing) a record.
//Override is to accomidate couchdb and that it doesn't like like to see a revision or rev
//when creating a record. But because our model contains a rev (which is used for updates
//or patch request) we need to make sure during a POST request that we cut or remove the rev
//property out of the payload. Since Ember-Data sets it to null (record is about to be added)
//removing it won't hurt a thing.
serialize(snapshot, options) {
let data = this._super(...arguments);
if (data.data.attributes.rev === null) {
delete data.data.attributes.rev;
}
return data;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment