0
votes

I have an app model and apps have an id and name.

  this.resource("apps", function() {
    this.route('show', { path: ':app_id' });
  });

I'd like to make the show view show metrics about the app, but the query is pretty intense, so I don't want to include it in the call to the index view (let's say this is a table).

I'm not sure if this is possible with ember-data because the app would already be in the store with the simplified payload and not be re-requested for the show view to get the metrics.

Then my head went to making metrics a completely different model accessible from apps/1/metrics and then making it another model and everything.

But if I sideload the data, i have to provide ID references to the metrics for a particular app. And it's hasOne so there's not really IDs as there would be for a database backed model.

What's the best way to load in additional data about a model or expand the information supplied in the show view?

The backend is Rails and this is an ember-cli project.

1

1 Answers

1
votes

The easiest way is to retrieve the data in the Route's afterModel handler:

var ShowRoute = Ember.Route.extend({
  model: function(params) {
    // Load the model and return it.
    // This will only fire if the model isn't passed.
  },
  afterModel: function(model, transition) {
    // Load the rest of the data based on the model and return it.
    // This fires every time the route re-loads (wether passed in or via model method).
  }
});