How can I load seed data for my app?

Hi everyone,

We have some constant data that we need to load from the server once when our Ember app boots. This is basic stuff like the copy for our error messages, etc… The reason we don’t hard code this in the Ember app is that we want our marketing team to own the copy in their CRM.

What’s the best way to load this data in? Basically, I want to do a this.store.findAll('constants') to initialize the constants service that will be used in the rest of the app.

Any help would be greatly appreciated.

Thanks!

We still use the fixture adapter for this. Our Ember 2.0 fork is here:

https://github.com/martinic/ember-data-fixture-adapter

If you need a adapter example I have to lookup the code on an other system.

How do you load the data from the back-end? We might be talking about 2 different issues. I’m fine using the JSONAPIAdapter, I just want to findAll once and then peekAll (for example) in the rest of my routes.

You can just do this in your application route’s beforeModel hook. E.g.

beforeModel: function() {
  return Ember.RSVP.all([
    this.get('store').findAll('static-model-type-1'),
    this.get('store').findAll('static-model-type-2'),
  ]);
}

And then, as you mentioned, just use this.get('store').peekRecord() from then on.

Thanks. I’ll give that a try. We’d experimented with it before and it didn’t seem like the hooks in ApplicationRoute were blocking for the promise it returns to resolve.

I’ll try again to make sure there’s nothing that I’m missing.

Oh I misunderstood your question. Glad @francesconovy didn’t :wink: