albertjan
albertjan

Reputation: 7817

ember-data async hasMany requests

I have a model that looks like:

export default DS.Model.extend({
  ordernumber: DS.attr('string'),
  allowMeasurementsFrom: DS.attr('date'),
  devices: DS.hasMany('device', { async: true })
});

And when I do a request to a page that is about one order I get these requests:

GET "http://localhost:51799/devices/0fd27d12-fd25-412d-bcf6-6e84064bd951".
GET "http://localhost:51799/devices/a84142bd-b314-4e6e-a29f-6821fb7f32fb".
GET "http://localhost:51799/devices/3b1ed530-1cf6-42fb-90b7-f1d4886dce05".

But I expected a request with multiple ids, like it says in the docs here. Like:

GET "http://localhost:51799/devices?ids[]=3b1ed530-1cf6-42fb-90b7-f1d4886dce05&ids[]=a84142bd-b314-4e6e-a29f-6821fb7f32fb&ids[]=3b1ed530-1cf6-42fb-90b7-f1d4886dce05".

And this is my template:

{{id}}

{{#each dev in devices}}
  <img {{bind-attr src=dev.image}}>
  {{dev.deviceId}}
{{/each}}

I've tried looping through the devices directly and getting them in the controller first and then, looping through the devices. In both cases it does n requests.

I'm using the DS.RESTAdapter. Versions: Ember: 1.10.0 Ember Data: 1.0.0-beta.15

Upvotes: 1

Views: 277

Answers (1)

GJK
GJK

Reputation: 37389

The information I had was a bit out of date. Luckily the information you need is fairly reasonably documented. You want the coalesceFindRequests property. Set that to true in your adapter and it should coalesce them like you see in the guide. If you haven't overridden the adapter yet, you can do so by creating a adapters/application.js file that looks like this:

export default DS.RESTAdapter.extend({
    coalesceFindRequests: true
});

Upvotes: 2

Related Questions