MODEL_FACTORY_INJECTIONS and Fixtures
-
21-12-2019 - |
Question
When you generate a project using ember-cli you will have MODEL_FACTORY_INJECTIONS
turned on by default.
But for some reason it breaks fixture loading:
adapters/application
export default DS.FixtureAdapter.extend({});
models/note
var Note = DS.Model.extend({
text: DS.attr('string'),
});
Note.FIXTURES = [
{
id: 1,
text: 'text1'
},
];
export default Note;
routes/index
export default Ember.Route.extend({
model: function() {
return this.store.find('note');
}
});
With MODEL_FACTORY_INJECTIONS
I get
Error while loading route: Error: Assertion Failed: Unable to find fixtures for model type notes@model:note:
And without everything works as expected.
Maybe I've missed something? Or is that just a bug?
Solution
I don't know what MODEL_FACTORY_INJECTIONS
does but I also discovered that my fixtures don't work if it is enabled. Based on this question I found a solution where you don't have to disable it. You have to use reopenClass
to define the fixtures so they get picked up correctly.
var Note = DS.Model.extend({
text: DS.attr('string'),
});
Note.reopenClass({
FIXTURES: [
{
id: 1,
text: 'text1'
}
]
});
export default Note;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow