0
在JSON API中,我需要表示主数据对象与其自身之间具有多对多关系的主数据集合。JSON Api如何在主数据中表示对象中的多对多关系
即。
account1 -> canTransferTo (relationship) -account3
account2 -> canTransferTo (relationship) -account1, account3
account3 -> canTransferTo (relationship) -account1
我该怎么做才能遵循JSO API规范。它可以像这样下面?
{
"data": [{
"type": "accounts",
"id": "1",
"attributes": {
"name": "account1"
},
"relationships": {
"canTransferTo": {
"links": {
"self": "http://example.com/accounts/1/relationships/canTransferTo",
"related": "http://example.com/accounts/1/canTransferTo"
},
"data": {
"type": "accounts",
"id": "3"
}
}
},
"links": {
"self": "http://example.com/accounts/1"
}
}, {
"type": "accounts",
"id": "2",
"attributes": {
"name": "account2"
},
"relationships": {
"canTransferTo": {
"links": {
"self": "http://example.com/accounts/2/relationships/canTransferTo",
"related": "http://example.com/accounts/2/canTransferTo"
},
"data": [{
"type": "accounts",
"id": "1"
}, {
"type": "accounts",
"id": "3"
}]
}
},
"links": {
"self": "http://example.com/accounts/2"
}
}, {
"type": "accounts",
"id": "3",
"attributes": {
"name": "account3"
},
"relationships": {
"canTransferTo": {
"links": {
"self": "http://example.com/accounts/3/relationships/canTransferTo",
"related": "http://example.com/accounts/3/canTransferTo"
},
"data": {
"type": "accounts",
"id": "1"
}
}
},
"links": {
"self": "http://example.com/accounts/3"
}
}]
}
哦!非常感谢!这很有帮助 – inforeqd
很高兴帮助! p.s .:接受我的答案,如果它有助于解决您的问题;) – Pavol