Where should I define fixtures in an Ember JS app generated with ember-cli? I've tried numerous places, such as app.js
and within a folder called "fixtures".

- 2,997
- 4
- 29
- 40
-
Did you ever figure this out? I generated an app using ember-cli and read the guides over and over and still can't get them working. – Stoutie Apr 13 '14 at 04:36
-
1@stoutie I figured it out and wrote an answer. I hope it helps you out! – stravid Apr 14 '14 at 09:17
4 Answers
After digging around I discovered that changing Ember.MODEL_FACTORY_INJECTIONS = true;
in the file app.js
to Ember.MODEL_FACTORY_INJECTIONS = false;
is solving the problem.
Through this question I also found another solution where you don't have to change the configuration:
Instead of defining the fixtures as described you have to use reopenClass
:
//models/item.js
var Item = DS.Model.extend({...});
Item.reopenClass({
FIXTURES: [
{ id: 1, ... },
{ id: 2, ... }
]
});
export default Item
Happy developing with Ember and ember-cli :-)
-
a warning that may not apply but worth mentioning, a few weeks I had a n issue with the LocalStorage adapter which was caused by Ember App Kit setting the factory injections to false by default. This caused them to set it to true in the HEAD see (#565)[https://github.com/stefanpenner/ember-app-kit/issues/565] – Amr Draz Apr 14 '14 at 20:04
Instead of using fixtures, the way I'm doing it in Ember CLI 0.0.40 is generating api stubs.
ember generate api-stub tasks
I'm a node.js beginner, but from the looks of it, it sets up an express server script to respond to the /tasks
endpoint, corresponding to the name you pass to the command, in the format the Ember REST adapter is expecting. Then you simply fill in the empty array with your fixture data. Easy peesy!
The benefit I see is that I won't have to rework anything later to integrate with a restful api getting me one step closer to launching a real app some day.
This generator is not thoroughly documented yet. It's only displayed as an item in the ember help generate
command, which I was brave/desperate/curious/stupid enough to try.

- 1,944
- 1
- 21
- 17
-
1The command is nowadays `ember g http-mock
` (running ember-cli 0.1.2-master-f353e3e216) – Timo Nov 12 '14 at 12:24
If you use findQuery to get your data you will get this error when using the method above:
Error while loading route: Error: Assertion Failed: Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store.
To fix this I created an adapter for the model and implemented the queryFixtures
method to return the fixtures.
#/adapters/[model-name].js
queryFixtures: function() {
return [ {
"key" : "value",
},
{
"key" : "value",
},
etc...
]
};
I had to do this in addition to reopenClass
in my model definition as stated above. In fact it was the same data, I cut and pasted. This smells a little bad, but it works. I'm sure there's a better way to do this without duplicating the fixtures, I just don't know what it is.

- 321
- 1
- 6
- 17
I define it in the model folder
//models/item.js
var Item = DS.Model.extend({...})
Item.FIXTURES = [
{
id:1,
...
}
];
export default Item

- 2,806
- 3
- 20
- 26
-
1I haven't seen models or fixtures defined like this before in ember-cli. It seems as though the `export default DS.Model.extends({})` is the suggested route. Any way to define the fixtures under this structure? – YWCA Hello Apr 01 '14 at 16:49
-
I modified my code to clarify what I meant by the ... at the end. The reason I kept it ... is because if you're using a node server it would be `module.exports = Item` – Amr Draz Apr 02 '14 at 19:55
-
@AmrDraz Did you actually try this in an app generated using ember-cli? Something is missing because it's still not working for me. – Stoutie Apr 13 '14 at 04:38
-
@stoutie It's pretty obvious that @AmrDraz did not test this specific answer since he said `.extends`, a non-existent function, instead of `.extend`. And even with the correct function name it doesn't work. It's likely that he typed it from memory, and there is an option somewhere else in the app, set weeks ago and long gone from memory, that is making this work. – Jeffrey Biles Apr 14 '14 at 03:37
-
2
-
1@stoutie I did actually type it from memory on my phone on my way to work (not the best developing environment) I modified the extends typo to extend, however it should be noted that using .FIXTURES works just the same as using reopenClass then typing FIXTURES, tho generally using reopenClass would be a better good case practice. will not answer questions from phone again I guess XD – Amr Draz Apr 14 '14 at 19:58
-
@YWCAHello looking at this I think you need to rewrite the current default model that ember-cli creates. So you need to explicitly declare it as a var and then export it at the end. Like the accepted answer above. I havent found any solution other than that. So instead of `export default DS.Model.extend...` use `var whatever = DS.Model.extend` and then export it at the end. I can confirm that this works. – Craicerjack May 20 '14 at 09:56