modelNameFromPayloadType (payloadType) String
public
modelNameFromPayloadType
can be used to change the mapping for a DS model name, taken from the value in the payload.
Say your API namespaces the type of a model and returns the following payload for the post
model:
// GET /api/posts/1 { "data": { "id": 1, "type: "api::v1::post" } }
By overwriting modelNameFromPayloadType
you can specify that the post
model should be used:
app/serializers/application.js
import DS from "ember-data"; export default DS.JSONAPISerializer.extend({ modelNameFromPayloadType(payloadType) { return payloadType.replace('api::v1::', ''); } });
By default the modelName for a model is its singularized name in dasherized form. Usually, Ember Data can use the correct inflection to do this for you. Most of the time, you won't need to override modelNameFromPayloadType
for this purpose.
Also take a look at payloadTypeFromModelName to customize how the type of a record should be serialized.
Parameters:
-
payloadType
String
- type from payload
Returns:
-
String
- modelName
Please login to continue.