Skip to content

Instantly share code, notes, and snippets.

@caligo-mentis
Created October 1, 2012 06:57
Show Gist options
  • Save caligo-mentis/3809981 to your computer and use it in GitHub Desktop.
Save caligo-mentis/3809981 to your computer and use it in GitHub Desktop.
Fragment of ember.js data adapter which ask for data after commit
createRecord: function(store, type, model) {
var primaryKey = get(model, 'primaryKey');
var url = this.urlFor(type);
var id = this.nextUUID();
var data = model.toJSON();
data[primaryKey] = id;
return this.ajax(url + "/create", "POST", { data: JSON.stringify(data), contentType: 'application/json' }).pipe(function(json) {
var filter = {};
filter[primaryKey] = id;
return this.ajax(url + this.queryString({ filter: filter, limit: 1 }), "GET").done(function(json) {
store.didCreateRecord(model, json[0]);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment