0
votes

When upgrading EmberData from 1.0.0-beta.9 to 1.0.0-beta.10 I've noticed that the same OPTIONS/GET request is made multiple times when using a computed property in various places of the page.

Sample Code

http://jsbin.com/moruj/1/

Then in my request, I see 3 option calls to my events API. This wasn't happening in beta.9 so I'm curious what may have happened?

2
what's your Route like? are you using this.store.find('someModel')?MilkyWayJoe
Yup. I'm doing this.store.find('customer')alvincrespo
That's exactly why then... I think find always sends a request. Try using find in the parent level only (in the resource route) and use all instead in the index route (or whatever route you're actually displaying data)MilkyWayJoe
Hmm. Not sure I follow. The multiple requests that I'm getting is not from the /customers API but from the /events API. So in the end I get a customer, but I'm getting 3 requests to my events API - which would then be 6 because 3 OPTIONS / 3 GETS :(alvincrespo

2 Answers

1
votes

Before answering your question, I have to say the code in your question is wrong. Please check and modify your code so more people can understand it.

For example in your code:

/* It should be App.Customer right? */
App.CustomerModel = DS.Model.extend({});

/* should be App.CustomerIndexRoute ? */
App.CustomerIndexController = Ember.Route.extend({
  model: function(params) {
    /* it returns a promise which resolves a customer array */
    return this.store.find('customer');
  }
});

App.CustomerIndexController = Ember.Controller.extend({
  /*
   * But for a customer array you can not get events property.
   * you can only get events from a single customer.
   */
  filteredEvents: function() {
    return this.get('events').slice(0, 10);
  }.property('events')
});

For multiple GET requests for events

No matter how you construct your route & controller code, when you iterate events for a customer, Ember Data sends a request /events/:id for each un-fetched event. You can set coalesceFindRequests: true in your adapter to load events in one request, like /events/ids[]=1&ids[]=2&ids[]=3.

For multiple OPTION requests

Please check if you use proxy to delegate ajax requests to a remote server or a mock server. As I know an OPTION request will appear when your proxy can not delegate the request correctly. In this case you may see an OPTION request and a GET request at the same time. It's not an Ember Data problem.