-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How could I use put method to update a record instead of patch method #3870
Comments
For now, I use the following hack. Is there a better way to do this?
|
#3099 aims to allow easier overwriting of the made request. |
#3099 has been merged and is available in Having this flag enabled, you can do this in your adapter to make a // app/adapters/application.js
import JSONAPIAdapter from "ember-data/adapters/json-api";
export default JSONAPIAdapter.extend({
methodForRequest({ requestType }) {
if (requestType === "updateRecord") {
return "PUT";
}
return this._super(...arguments);
}
}); |
I am using emberjs 2.16 which does "options" method call for update out of the box (I have never seen options used anywhere else as rest API law). I am trying to have emberjs do all update calls to server as PUT. Unfortunately both of these did not work for me updateRecord: function (store, type, snapshot) {
var data = {};
var serializer = store.serializerFor(type.modelName);
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });
var id = snapshot.id;
var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord');
return this.ajax(url, 'PUT', { data: data });
} And methodForRequest({ requestType }) {
if (requestType === "updateRecord") {
return "PUT";
}
return this._super(...arguments);
} Now I can not move any further. save() {
this.get('model').save().then(
() => this.transitionToRoute('calendars'),
() => console.log('error saving')
);
}, |
The overriding-updateRecord-approach works for me, see this twiddle... 🤔 do you spot any differences to your code? |
works thanks |
No description provided.
The text was updated successfully, but these errors were encountered: