mardi 11 octobre 2016

How do I customize the URL that Ember RESTAdapter calls?

In our Ember application, I have 3 different models:

  • organizations
  • users
  • issues

Issues are created by users who belong to an organization. Both organizations and users have an issues array with a bunch of issue IDs that belong in the issues model. For example, this is what the users model looks like:

// app/models/users.js
export default DS.Model.extend({
    name: DS.attr('string'),
    email: DS.attr('string'),
    belongsTo: DS.belongsTo('organizations'),
    issues: DS.hasMany('issues')
});

We have two APIs to view a list of all issues:

  • GET /users/:userId/issues - This API gets all the issues created by the user
  • GET /organizations/:organizationId/issues - This API gets all the issues created by users that belong to this organization

The issue is, when I call this.store.findAll('issues');, the Ember RESTAdapter calls GET /issues by default. I can't figure out a way to get the RESTAdapter to call any of the URLs above. I can't use this.store.findRecord('issues', 1); because that calls a specific issue by ID like GET /issues/:issueId. How can I get the RESTAdapter to call the above URLs without having to manually make an AJAX request and push the API response to Ember Data?




Aucun commentaire:

Enregistrer un commentaire