在 Json:api 规范中包含具有相同 ID 和类型的关系
Included relationships with same id and type in Json:api specification
我发送了这样的回复(执行此回复的代码是正确的,我不需要代码):
"data": [
{
"type": "participant",
"id": "c15409",
"attributes": {
"licenseNumber": "",
"givenName": "Valeria Alejandra",
"familyName": "Snchez Arredondo",
"passportGivenName": "VALERIA ALEJANDRA",
},
"relationships": {
"organization": {
"data": {
"type": "organization",
"id": "1205"
}
}
}
},
{
"type": "participant",
"id": "c16733",
"attributes": {
"licenseNumber": "",
"givenName": "Amir",
"familyName": "Mota Castaeda",
"passportGivenName": "AMIR",
},
"relationships": {
"organization": {
"data": {
"type": "organization",
"id": "1205"
}
}
}
},
"included": [
{
"type": "organization",
"id": "1205",
"attributes": {
"name": "Team",
"country": "USA"
}
},
{
"type": "organization",
"id": "1205",
"attributes": {
"name": "Team",
"country": "USA"
}
},
]
Json:api
不允许有相同的id和类型所以这个回复是不正确的,但我需要几个参与者可以属于同一个组织。我想显示组织属性,因为请求资源的人需要这些数据。不知道下一个结构对不对:
"data": [
{
"type": "participant",
"id": "c15409",
"attributes": {
"licenseNumber": "",
"givenName": "Valeria Alejandra",
"familyName": "Snchez Arredondo",
"passportGivenName": "VALERIA ALEJANDRA",
},
"relationships": {
"organization": {
"data": {
"type": "organization",
"id": "1205"
}
}
}
},
{
"type": "participant",
"id": "c16733",
"attributes": {
"licenseNumber": "",
"givenName": "Amir",
"familyName": "Mota Castaeda",
"passportGivenName": "AMIR",
},
"relationships": {
"organization": {
"data": {
"type": "organization",
"id": "1205"
}
}
}
},
"included": [
{
"type": "organization",
"id": "1205",
"attributes": {
"name": "Team",
"country": "USA"
}
}
我的母语不是英语,但我想很明显我不是在问为什么这段代码不起作用。我只是想知道我所做的结构 是否正确。是或否是有效答案。无论如何,感谢回答我的 Ryan。
可能你的json结构不对,检查一下json结构是否符合你的需要。
{
"data":[
{
"type":"participant",
"id":"c15409",
"attributes":{
"licenseNumber":"",
"givenName":"Valeria Alejandra",
"familyName":"Snchez Arredondo",
"passportGivenName":"VALERIA ALEJANDRA"
},
"relationships":{
"organization":{
"data":{
"type":"organization",
"id":"1205"
}
}
}
},
{
"type":"participant",
"id":"c16733",
"attributes":{
"licenseNumber":"",
"givenName":"Amir",
"familyName":"Mota Castaeda",
"passportGivenName":"AMIR"
},
"relationships":{
"organization":{
"data":{
"type":"organization",
"id":"1205"
}
}
}
}
],
"included":[
{
"type":"organization",
"id":"1205",
"attributes":{
"name":"Team",
"country":"USA"
}
}
]
}
查看官方文档:https://jsonapi.org/format/#document-compound-documents
我发送了这样的回复(执行此回复的代码是正确的,我不需要代码):
"data": [
{
"type": "participant",
"id": "c15409",
"attributes": {
"licenseNumber": "",
"givenName": "Valeria Alejandra",
"familyName": "Snchez Arredondo",
"passportGivenName": "VALERIA ALEJANDRA",
},
"relationships": {
"organization": {
"data": {
"type": "organization",
"id": "1205"
}
}
}
},
{
"type": "participant",
"id": "c16733",
"attributes": {
"licenseNumber": "",
"givenName": "Amir",
"familyName": "Mota Castaeda",
"passportGivenName": "AMIR",
},
"relationships": {
"organization": {
"data": {
"type": "organization",
"id": "1205"
}
}
}
},
"included": [
{
"type": "organization",
"id": "1205",
"attributes": {
"name": "Team",
"country": "USA"
}
},
{
"type": "organization",
"id": "1205",
"attributes": {
"name": "Team",
"country": "USA"
}
},
]
Json:api
不允许有相同的id和类型所以这个回复是不正确的,但我需要几个参与者可以属于同一个组织。我想显示组织属性,因为请求资源的人需要这些数据。不知道下一个结构对不对:
"data": [
{
"type": "participant",
"id": "c15409",
"attributes": {
"licenseNumber": "",
"givenName": "Valeria Alejandra",
"familyName": "Snchez Arredondo",
"passportGivenName": "VALERIA ALEJANDRA",
},
"relationships": {
"organization": {
"data": {
"type": "organization",
"id": "1205"
}
}
}
},
{
"type": "participant",
"id": "c16733",
"attributes": {
"licenseNumber": "",
"givenName": "Amir",
"familyName": "Mota Castaeda",
"passportGivenName": "AMIR",
},
"relationships": {
"organization": {
"data": {
"type": "organization",
"id": "1205"
}
}
}
},
"included": [
{
"type": "organization",
"id": "1205",
"attributes": {
"name": "Team",
"country": "USA"
}
}
我的母语不是英语,但我想很明显我不是在问为什么这段代码不起作用。我只是想知道我所做的结构 是否正确。是或否是有效答案。无论如何,感谢回答我的 Ryan。
可能你的json结构不对,检查一下json结构是否符合你的需要。
{
"data":[
{
"type":"participant",
"id":"c15409",
"attributes":{
"licenseNumber":"",
"givenName":"Valeria Alejandra",
"familyName":"Snchez Arredondo",
"passportGivenName":"VALERIA ALEJANDRA"
},
"relationships":{
"organization":{
"data":{
"type":"organization",
"id":"1205"
}
}
}
},
{
"type":"participant",
"id":"c16733",
"attributes":{
"licenseNumber":"",
"givenName":"Amir",
"familyName":"Mota Castaeda",
"passportGivenName":"AMIR"
},
"relationships":{
"organization":{
"data":{
"type":"organization",
"id":"1205"
}
}
}
}
],
"included":[
{
"type":"organization",
"id":"1205",
"attributes":{
"name":"Team",
"country":"USA"
}
}
]
}
查看官方文档:https://jsonapi.org/format/#document-compound-documents