Updating Ember Data relationships and saving them to the server


#1

Edit: never mind. Looks like my backend wasnt allowing those headers lol…

I’m wondering if I’m not doing something correctly, or if I have found a bug and was wondering if anyone could take a look. I’ve looked everywhere and this is what I constantly see on updating them:

Lets say I have a report model and a dashboard model:

// Report model
export DS.Model.extend({
   name: DS.attr('name'),
   category: DS.belongsTo('category', {
      async: true
   }),
   dashboards: DS.hasMany('dashboard', {
      async: true
   })
});

// Dashboard model
export DS.Model.extend({
   name: DS.attr('name'),
   reports: DS.hasMany('report', {
      async: true
   })
});

Lets say that the user wants to add a report (28) to a dashboard (1). Example:

var report = this.store.find('report', 28);
var dashboard = this.store.find('dashboard', 1);

dashboard.then(function(dash) {
   dash.get('reports').addObject(report);
   dash.save();
});

Shouldn’t this then send a request to the server to save this relationship? From what I’m getting, this is Chrome’s output for the request:

Remote Address:127.0.0.1:443
Request URL:https://api.example.com/dashboard/1
Request Method:OPTIONS
Status Code:200 OK

Response Headers
Access-Control-Allow-Headers:
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin:https://reports.example.com
Access-Control-Max-Age:0
Connection:keep-alive
Content-Type:text/html
Date:Mon, 20 Jul 2015 16:48:17 GMT
Server:nginx/1.9.2
Transfer-Encoding:chunked
X-Powered-By:PHP/5.4.43

Request Headers
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:PUT
Connection:keep-alive
CSP:active
Host:api.example.com
Origin:https://reports.example.com
Referer:https://reports.example.com/report/28
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/43.0.2357.130 Chrome/43.0.2357.130 Safari/537.36

My first question is, why does it not include anything in the request that I’m trying to add report 28 to dashboard 1? Also, why is it using “OPTIONS” instead of “PUT”?