Slevin
Slevin

Reputation: 4222

How to load resources together (like /tasks?ids=1,2,3)?

How can I load multiple resources within one request in Ember.js?

I'm loading all my projects and want to display a list of all tasks that are assigned to this project, like:

Project 1
  Task 1
  Task 2
  Task 3
Project 2
  Task 1
  Task 2
  Task 3

My route returns all projects... (I've set tasks: DS.hasMany('task', {async: true}) in my project model):

model: function() {
  return this.store.find('project');
}

...and my templates shows them and their tasks:

{{#each project in projects}}
  {{project.name}}
  {{#each task in project.tasks}}
    {{task.status}}
  {{/each}}
{{/each}}

But now ember fires dozens of requests for each single task. I wonder how to group them, so Ember just have to make one request for all tasks of a project (something like /tasks?ids=1,2,3)?

I'm using Ember, Ember-Data, a Rails API-Backend and Ember's ActiveModelAdapter and ActiveModelSerializer.

That's how my API returns a single project (like /projects/1):

enter image description here

Upvotes: 0

Views: 45

Answers (1)

Slevin
Slevin

Reputation: 4222

Just forgot to add embed_in_root: true to my serializers.

Upvotes: 0

Related Questions