CrshOverride / ember-web-api

Ember Data Addon for .NET Web API Endpoints
MIT License
20 stars 12 forks source link

TypeError: Cannot read property 'pluralize' of undefined with belongsTo or hasMany relationship #1

Closed elanclarkson closed 9 years ago

elanclarkson commented 9 years ago

Getting the following error when attempting to make a belongsTo or hasMany relationship:

Error while processing route: home Cannot read property 'pluralize' of undefined TypeError: Cannot read property 'pluralize' of undefined

This traces to line 84 of the serializer: var key = type.modelName.pluralize() inside the sideLoadItem method.

It would appear that 'type' is only a string containing the name of my model and therefore type.modelName is undefined.

Has this been caused by changes in the underlying Ember Data API? Please see my version information below and let me know if you need anything else. Thanks.

Ember: 1.13.7 Ember Data: 1.13.8 jQuery: 1.11.3

CrshOverride commented 9 years ago

Sorry about the long delay in responding to this. For some reason, I didn't get any GitHub notifications and didn't realize that an Issue had been submitted. I will start looking into this tonight and see if I can reproduce the error.

CrshOverride commented 9 years ago

It definitely looks like Ember Data 1.13.8 changed the way that the relationship was passed around. I've added a check for the type of relationship.type. If a string is found, it will look up the model from the store. A quick test showed that this fixed the issue in my simple sample app.

I'm not currently able to test the serialization back to the server but, after a quick look at the code, I think it should still work.