1
votes

I have an Ember data model named Activity.

Depending on my current route, I need to call services to populate the store with activities from different API namespaces. So while my current ActivityAdapter looks like this:

App.ActivityAdapter = DS.RESTAdapter.extend({
    namespace: 'services/activities'
});

I really want it to look like this:

App.ActivityAdapter = DS.RESTAdapter.extend({
    if (this.get('currentRoute') === "user") {
        namespace: 'services/users/activities'
    } else {
        namespace: 'services/activities'
    }
});

I can't seem to find a solution for this, and the best I can think of right now is a hack that involves creating a separate UserActivity model that basically has the same properties as the Activity model, and then specifying a separate UserActivityAdapter.

Has anyone else run into this issue? Any input is appreciated!

1

1 Answers

0
votes

Do you control your API on the server? If so, you could simply change your /services/activities endpoint to accept an optional userId query param.

So you will always target the same namespace:

  • GET /services/activities => returns all activities
  • GET /services/activities?userId=123 => return activities for user 123

This is a common pattern in REST APIs. But maybe I misunderstood your problem?