mercredi 21 octobre 2015

ember data debug model deserialisation

I have an ember application that is getting its data from a REST API.

I have a particular model contacts that is not being processed correctly.

There are no error messages such as you get if you spell the model name wrong. The payload for the index route contains about 1500 contacts like so:

{"contacts":
   [{"id":1,
     "type":"customer",
     "foreign_key":1242,
     "first_name":"John",
     "last_name":"Smith",
     ...
     "created_at":"-0001-11-30 00:00:00",
     "updated_at":"-0001-11-30 00:00:00",
     "customer_id":1242
    },
     ...
   ]
}

The JSON response looks OK when I look in the Network tab. The browser is able to parse and display the response nicely.

I have compared the response to similar models and the format looks the same to me.

In the ember inspector, under Data I get 1 contact with id=null and other fields undefined.

The contact model is:

import DS from 'ember-data';
export default DS.Model.extend({
  type:           DS.attr('string'),
  foreign_key:    DS.attr('number'),
  first_name:     DS.attr('string'),
  last_name:      DS.attr('string'),
  ... more strings 
  created_at:     DS.attr('string'),
  updated_at:     DS.attr('string'),
  customer:       DS.belongsTo('customer')  
});

ember 2.0.2
ember-data 2.0.0
using pod structure

How can I investigate further? It looks like the response is not being parsed and turned into contact models properly.




Aucun commentaire:

Enregistrer un commentaire