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