dimanche 5 août 2018

Nested list of objects not getting deserialized in emberjs

I have a /reports api that returns an output like :

 {
  "data": {
    "id": 87,
    "type": "reports",
    "attributes": {
      "status": "STARTED",
      "startdatetime": 1532511531000,
      "enddatetime": 1533485380052,
      "queries": [
       {
        "startdatetime": 1532511531000,
        "enddatetime": 1533485380056,
        "reportId": 87,
        "id": "Q1"
      }
    ]
   }
  }
}

The models looks like:

model/report.js

status: DS.attr('string'),
startdatetime: DS.attr('number'),
enddatetime: DS.attr('number'),
queries: DS.hasMany('query')

model/query.js :

report : DS.belongsTo('report'),
startdatetime: DS.attr('number'),
enddatetime: DS.attr('number')

In my component (template.js), I try to access the queries and it seems to not be able to deserialize it right :

queriesLength: Ember.computed('report', function(){
  return this.get('report').get('queries').length;
}

Running queriesLength() returns 0 for the above mentioned json.

1) There are no issues in the console.log.

2) The browser network shows that the api returned the output correctly.

3) When accessing other properties like startdatetime, it returns the right value.

Is the model/api response missing something?




Aucun commentaire:

Enregistrer un commentaire