[Solved] Tutorial Question: Findall

I’m reading the tutorial. I’ve got a good idea about how the design works and what to do with it, but I’m having a problem translating the tutorials code in index.js into what it actually calls. To be clear, the line in question is this:

return this.store.findAll('rental');

I understand what this is doing in terms of the data store. What I don’t understand is why this translates to a GET call to /rentals. Can someone explain this? Thanks.

I think the place you’ll want to start is in the Customizing Adapters section of the guides. If you’re getting comfortable with that, then you could dig into the API docs a little bit. It’s this hook that actually translates the findAll and rental into GET /rentals. It’s actually a giant switch statement if you look under the hood:

  // From https://github.com/emberjs/data/blob/v2.3.0/addon/-private/adapters/build-url-mixin.js#L52
  buildURL: function(modelName, id, snapshot, requestType, query) {
    switch (requestType) {
      case 'findRecord':
        return this.urlForFindRecord(id, modelName, snapshot);
      case 'findAll':
        return this.urlForFindAll(modelName);
      case 'query':
        return this.urlForQuery(query, modelName);
      case 'queryRecord':
        return this.urlForQueryRecord(query, modelName);
      case 'findMany':
        return this.urlForFindMany(id, modelName, snapshot);
      case 'findHasMany':
        return this.urlForFindHasMany(id, modelName);
      case 'findBelongsTo':
        return this.urlForFindBelongsTo(id, modelName);
      case 'createRecord':
        return this.urlForCreateRecord(modelName, snapshot);
      case 'updateRecord':
        return this.urlForUpdateRecord(id, modelName, snapshot);
      case 'deleteRecord':
        return this.urlForDeleteRecord(id, modelName, snapshot);
      default:
        return this._buildURL(modelName, id);
    }
  }
2 Likes

Okay, that makes perfect sense. Thank you for that link. So it calls rentals because the url builder automatically makes the call to rental plural.

Thanks for the explanation and links to the manual.

This was driving me up the wall up bit too - thank you for the question and answer.

For future ember novices is there a way we can recommend they add the two links you provided at the point they go over Ember-Data hooking for the first time in the tutorial?

Thank you again!