I encountered a strange issue with the ember-data framework today. My application namespace is METAMORE, I defined a Model called ‘Strata’. I override the function extractSingle in the ApplicatoinSerializer. The error below happened when the extractSingle was called.
strata.index No model was found for ‘stratum’ Error: No model was found for ‘stratum’
It is because the framework try to find the model type with the typekey of the my model METAMORE.Strata. However, the METAMORE.Strata.typeKey returns ‘stratum’.
My ember-data version is 1.0.0-beta.9, My Model is defined as follows:
METAMORE.Model = METAMORE.OrganizationIdModel.extend({
createdOn: DS.attr('string'),
lastUpdatedOn: DS.attr('string'),
//isChecked is used only by the client side for checkboxes, server can never see it.
isChecked:false
});
METAMORE.Strata = METAMORE.Model.extend({
endpoint : DS.attr('string'),
username: DS.attr('string'),
password: DS.attr('string'),
daysToLoad: DS.attr('string'),
defaultDuration: DS.attr('string')
});
It had been working fine before I upgraded the ember-data to 0.9. It was 0.7 before.
Does anyone know what might be the cause? How the typeKey of a model type is computed? Why ‘a’ becomes ‘um’? Thanks.
Ember data uses something called Ember Inflector for pluralizing and singularizing keys. I’m going to make an assumption that there was an update in Ember Inflector that caused the change. If you look here you’ll see the rule that singularizes a word ending in “ta” to “tum”.
This Stack Overflow question answers how you can override the pluralization of certain words, if need be. (Make sure to see the answer on the bottom as the original answer applies to the pre-1.0 beta version).
I don’t know how to solve your problem. But by reading the source I think there is a workaround to solve your issue. You can manually set typeKey for your model class and Ember will respect that.
METAMORE.Strata.typeKey = 'strata';
But for long term it’s necessary to figure out the reason so your other models won’t have same issue.