mercredi 27 avril 2016

Error loading belongsTo relationship in Ember 2

I am having issues loading a belongsTo relationship - no errors get displayed, and no requests sent. The UI just remains blank. Given the following models:

project.js import DS from 'ember-data';

export default DS.Model.extend({
    name: DS.attr(),
    items: DS.hasMany('line-item', {async: true}),  
    customer: DS.belongsTo('customer', {async: false})  
});

customer.js

import DS from 'ember-data';

export default DS.Model.extend({
    name: DS.attr(),
    email: DS.attr(),
    projects: DS.hasMany('project', {async: true})  
});

The relationship between project and customer exists. When accessing the projects endpoint, the project gets correctly returned:

{  
   "data":{  
      "type":"projects",
      "id":"3861b834-e270-4296-b7be-9aca55676874",
      "attributes":{  
         "created":"2016-04-27T22:36:01.061349Z",
         "modified":"2016-04-27T22:36:01.061477Z",
         "name":"Sample name",
      },
      "relationships":{  
         "customer":{  
            "data":{  
               "type":"customers",
               "id":"9242bd41-6bb0-41ed-b5f3-21df26486d9e"
            }
         },
         "items":{  
            "meta":{  
               "count":0
            },
            "data":[  

            ]
         }
      }
   }
}

However when trying to access the customer, nothing happens (with nothing I mean: no console output, no request to the customers endpoint etc. The UI just fails to load):

this.get('project').get('customer');

Accessing other attributes works (including the project's items).

Any idea as to where I am going wrong?




Aucun commentaire:

Enregistrer un commentaire