Reputation: 8732
I use a FixtureAdapter to load the data locally when I'm developing the app.
These is my Page model with Fixture data:
App.Page = DS.Model.extend({
name : DS.attr('string'),
parent : DS.belongsTo('App.Page'),
subpages : DS.hasMany('App.Page')
});
App.Page.FIXTURES = [{
id: 1,
name: 'Home',
subpages: [ 2, 3, 4 ]
},{
id: 2,
name: 'About',
parent: 1
},{
id: 3,
name: 'Contact',
parent: 1
},{
id: 4,
name: 'Search',
parent: 1
},{
id: 5,
name: 'Blog',
parent: 2
}];
This is the code that returns all the Page objects in my Fixture
App.PagesRoute = Ember.Route.extend({
model: function() {
return App.Page.find();
}
});
This is my App.store:
App.store = DS.Store.create({
revision : 11,
adapter: DS.FixtureAdapter
});
This works great, but how do I return the root page?
When I change return App.Page.find()
in App.Page.findQuery(App.Page,{ id: 1 })
I get the following error:
Uncaught Adapter is either null or does not implement 'findQuery' method
-- UPDATE --
When I change return App.Page.find()
in App.Page.find({ name: 'Home' })
I get the following error:
Uncaught TypeError: Cannot call method '_create' of undefined
I guess that is because my data isn't loaded at that moment. But I thought that Ember would handle that for me.
Upvotes: 1
Views: 1716
Reputation: 3640
This works for Ember Data 0.13:
App.fixtureStore = DS.Store.create({
adapter: DS.FixtureAdapter.extend({
queryFixtures: function(fixtures, query, type) {
return fixtures;
}
})
});
And when testing be sure to do this:
App.store = App.fixtureStore;
DS.set('defaultStore', App.fixtureStore);
Upvotes: 2
Reputation: 5517
This is the proper way to define store:
App.Store = DS.Store.extend({
revision : 11,
adapter: DS.FixtureAdapter
});
Note the extend instead of create and capital letter S in Store. See Ember Guide for more info.
Upvotes: 0