I would like to prevent normalizing (dasherized by convention) of the model name and instead use the original name. I want to override the function 'normalizeModelName' as the page http://emberjs.com/api/data/#method_normalizeModelName suggests that this should be possible. But i'm not able to do so.
Simply assigning a new function to DS.normalizeModelName is returning an error: Cannot assign to read only property 'normalizeModelName' of object '[object Object]'
.
How could I prevent normalizing of the (internal) model name?
small warning: this is related to 2.10.0
i will not guarantee compatibility beyond or below this version. you need to dig through the corresponding files yourself.
since i had a similar problem i dug through the sourcecode of some ember-data stuff and came to the following conclusion:
you need to extend DS.JSONAPIAdapter
with pathForType(name)
wich essentially takes the name and camelizes as well as pluralizes it before it's being returned as plain text string.
this usually converts model names from foo-bar
to fooBars
by doing this: https://github.com/emberjs/data/blob/v2.10.0/addon/adapters/json-api.js#L134-L137
now about the opposite:
you need to extend DS.JSONAPISerializer
with keyForRelationship(key, typeClass, method)
where key
is essentially the model name aquired from relationships in your models. like: fooBar
this usually translates to foo-bar
by simply doing return dasherize(key);
https://github.com/emberjs/data/blob/v2.10.0/addon/serializers/json-api.js#L453-L455
you might to also dig through some other methods inside the serializer: modelNameFromPayloadKey
modelNameFromPayloadType
payloadKeyFromModelName
payloadTypeFromModelName
just throw in some debugger;
lines to see whats going through.