我有雇员和雇员两个模型
//employee model
import DS from 'ember-data';
export default DS.Model.extend({
empId : DS.attr(),
password : DS.attr(),
email : DS.attr(),
empdetails : DS.belongsTo("empdetails")
});
//empdetails model
import DS from 'ember-data';
export default DS.Model.extend({
firstName : DS.attr(),
lastName : DS.attr(),
dateOfJoining: DS.attr(),
employee : DS.belongsTo("employee")
});
我使用RESTAdapter进行REST调用。
//serializer
import DS from 'ember-data';
export default DS.JSONSerializer.extend({
});
当我尝试向员工发出获取请求时,出现以下错误
请检查您的序列化器,并确保其将关系有效载荷序列化为JSON API格式。错误:断言失败:在上遇到了一个不带belongsTo关系“ empdetails”类型的关系标识符,预期其类型为“ empdetails”的json-api标识符,但找到了“ {“ id”:“ 1”,“ firstName”:“ xxx “}
我从后端获取以下JSON
[
{
"id": 1,
"email": "xyz@gmail.com",
"password": "12345678",
"empdetails": {
"id": 1,
"firstName": "xxx",
"lastName": "yyy",
"dateOfJoining": "22-10-2018"
}
}
]
有人可以指导我纠正错误
答案 0 :(得分:2)
尝试如下更新您的员工序列化器:
import DS from 'ember-data';
export default DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
empdetails: {
serialize: 'records',
deserialize: 'records'
}
}});
有关更多详细信息,请参见this article。
答案 1 :(得分:0)
如果您使用Django Rest作为后端, 然后请使用DRF适配器和DRF串行器
Visit here了解更多信息