gpt4 book ai didi

ember.js - Ember js属于关系

转载 作者:行者123 更新时间:2023-12-02 17:03:23 24 4
gpt4 key购买 nike

我有两个模型 employee 和 empdetails

//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({
});

当我尝试为员工发出获取请求时,出现以下错误

Please check your serializer and make sure it is serializing the relationship payload into a JSON API format. Error: Assertion Failed: Encountered a relationship identifier without a type for the belongsTo relationship 'empdetails' on , expected a json-api identifier with type 'empdetails' but found '{"id":"1","firstName":"xxx"}

我从我的后端得到下面的 JSON

[
{
"id": 1,
"email": "xyz@gmail.com",
"password": "12345678",
"empdetails": {
"id": 1,
"firstName": "xxx",
"lastName": "yyy",
"dateOfJoining": "22-10-2018"
}
}
]

谁能指导我改正错误

最佳答案

尝试按如下方式更新您的员工序列化程序:

import DS from 'ember-data';

export default DS.JSONSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
empdetails: {
serialize: 'records',
deserialize: 'records'
}
}});

参见 this article了解更多详情。

关于ember.js - Ember js属于关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52927111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com