I’m having difficulty understanding how JSON-API represents relationship metadata.
Let’s say I have an objective and that objective has different concepts; but those concepts don’t all relate to the objective in the same manner; some are primary, some are secondary and some are tertiary.
So my primary resource, the objective, will have a relationships object that links it to the concepts. Here are the different options as I see them:
Option 1 - different objects for each relationship type:
{
“type”: “objective”,
“id”: “00559422-02E7-11DB-8468-BA18C3C820AE”,
“relationships”: {
“primary_concepts”: {
“data”: { “type”: “concept”, “id”: “02B7” }
},
“secondary_concepts”: {
“data”: { “type”: “concept”, “id”: “3AF6” }
},
“tertiary_concepts”: {
“data”: { “type”: “concept”, “id”: “CB23” }
},
}
Option 2 - different relationship types have different attributes:
{
“type”: “objective”,
“id”: “00559422-02E7-11DB-8468-BA18C3C820AE”,
“relationships”: {
“concepts”: [
{
“data”: { “type”: “concept”, “id”: “02B7” },
“attributes”: { “emphasis”: “primary” }
},
{
“data”: { “type”: “concept”, “id”: “3AF6” },
“attributes”: { “emphasis”: “secondary” }
},
{
“data”: { “type”: “concept”, “id”: “CB23” },
“attributes”: { “emphasis”: “tertiary” }
}
]
}
Option 3 - different relationship types have different meta:
{
“type”: “objective”,
“id”: “00559422-02E7-11DB-8468-BA18C3C820AE”,
“relationships”: {
“concepts”: [
{
“data”: {
“type”: “concept”,
“id”: “02B7”,
“meta”: { “emphasis”: “primary” }
}
},
{
“data”: {
“type”: “concept”,
“id”: “3AF6”,
“meta”: { “emphasis”: “secondary” }
}
},
{
“data”: {
“type”: “concept”,
“id”: “CB23”,
“meta”: { “emphasis”: “tertiary” }
}
},
]
}
I know Option 1 fits within the spec, but I would consider it bad design. Ideally, I’d go with Option 2, but is that allowed? What about Option 3, is that a compromise? Is there a 4th option I’m not considering?