I’m working on a project with Ember and a Python back-end. At the back-end I’m working with the marshmallow-jsonapi to provide a JSON API-compliant response. At the ‘motoristas/new’ route I’m sending a POST request that gets as response an object with the response code and the following body:
{
'data':[
{
'id':'145',
'attributes':{
'titulo-eleitor':'2132.1321.3213',
'nome-mae':'asdasda',
'identidade':'131231',
'naturalidade':'Amapá',
'cpf':'123.213.213-12',
'enderecos':{
'data':[
{
'id':'112',
'attributes':{
'estado':'AP',
'motorista-id':'145',
'cidade':'asdsadsa',
'logradouro':'asdsadsa',
'cep':'12.321-321',
'bairro':'asdasdsa'
},
'type':'enderecos_motorista'
}
]
},
'data-admissao':'2017-05-08T03:00:00+00:00',
'nome':'asdsada',
'nome-pai':'sdasdsa',
'email':'holanda.kamilla@gmail.com',
'pis-pasep':'212.32131.23-2',
'cnh':{
'data':[
{
'id':'119',
'attributes':{
'motorista-id':'145',
'categoria':'D',
'numero':'12321321321',
'data-vencimento':'2017-05-08 03:00:00'
},
'type':'cnh_motorista'
}
]
},
'matricula':'12312',
'carteira-trabalho':'2312321321',
'telefones':{
'data':[
{
'id':'111',
'attributes':{
'motorista-id':'145',
'numero':'21313-1213',
'ddd':'111',
'tipo-telefone':'Residencial'
},
'type':'telefones_motorista'
}
]
},
'cargo-id':'131',
'orgao-emissor-id':'SSPDF',
'escolaridade':'Ensino Fundamental',
'nome-conjuge':None,
'estado-id':'130',
'data-emissao-ct':'2017-05-08 03:00:00',
'estado-civil':'Solteiro(a)',
'conta-bancaria':{
'data':[
{
'id':'114',
'attributes':{
'tipo-conta':'Conta Corrente',
'banco':'001',
'motorista-id':'145',
'agencia':'12321321',
'numero-conta':'21321321'
},
'type':'conta_bancaria_motorista'
}
]
}
},
'type':'motoristas'
}
]
}
But I’m getting this error message: “Assertion Failed: ‘motorista’ was saved to the server, but the response does not have an id and your record does not either.”
I’m using the JSONAPIAdapter since I’m supposed to get a JSON API format compliant response:
import DS from 'ember-data';
import Ember from 'ember';
import ENV from 'sistran-frontend/config/environment';
export default DS.JSONAPIAdapter.extend({
namespace: ENV.APP.namespace,
pathForType(modelName) {
if (modelName === 'ordem-de-servico') {
return 'ordens-de-servico';
}
if (modelName === 'veiculo') {
return 'veiculos';
}
if (modelName === 'motorista') {
return 'motoristas';
}
},
});
I’m not sure why I’m getting this message because I have the id field on the response. What is wrong with the response that I’m sending to the Ember app? I have the ‘motoristas/index’ route that gets the same response object with the same body format and It’s working.