2

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?

somebody32
  • 179
  • 1
  • 1
  • 9

1 Answers1

9

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;
Community
  • 1
  • 1
stravid
  • 1,009
  • 7
  • 14
  • I found this post explaining what setting MODEL_FACTORY_INJECTIONS to true is used for. [Injecting a session](http://stackoverflow.com/questions/19997399/injecting-session-into-a-model) – Caranicas Aug 13 '14 at 21:05