payloadTypeFromModelName (modelname) Stringpublic
payloadTypeFromModelName can be used to change the mapping for the type in the payload, taken from the model name.
Say your API namespaces the type of a model and expects the following payload when you update the post model, which has a polymorphic user relationship:
// POST /api/posts/1
{
"post": {
"id": 1,
"user": 1,
"userType": "api::v1::administrator"
}
}
By overwriting payloadTypeFromModelName you can specify that the namespaces model name for the administrator should be used:
app/serializers/application.jsimport DS from "ember-data";
export default DS.RESTSerializer.extend({
payloadTypeFromModelName(modelName) {
return "api::v1::" + modelName;
}
});
By default the payload type is the camelized model name. Usually, Ember Data can use the correct inflection to do this for you. Most of the time, you won't need to override payloadTypeFromModelName for this purpose.
Also take a look at modelNameFromPayloadType to customize how the model name from should be mapped from the payload.
Parameters:
-
modelname
String - modelName from the record
Returns:
-
String - payloadType
Please login to continue.