I dont understand how to apply the JSONAPI framework on my particular problem. Hopefully someone can help. Let’s say I have a shop and clients order products. Asynchronously I ship parts from different orders to the client in one shipping. I have many orders to many shippings relationships and also one order to many shippings rlship.
Thus I have /orders/:id/shippings and I get:
"jsonapi": {
"version": "1.0"
},
"data": [
{
"type": "shippings",
"id": "5DDECEN",
"relationships": {
"products": {
"data": [
{
"type": "parts",
"id": "10PIQPD3"
},
{
"type": "parts",
"id": "10RAGPD3"
}
]
}
}
},
{
"type": "shippings",
"id": "5FK6CEN",
"relationships": {
"products": {
"data": [
{
"type": "parts",
"id": "10PIXPD3"
}
]
}...
This way I can follow up each ordered product in each shipping from each order etc. Now when it comes to the resource object of the relationship which is defined by the related route order/:id/shippings I would get all the products including their quantity and price etc. An here is also what I do not understand… if each product is from the type ‘part’ and I include all the parts in the order-shippings relationship I have different attributes compared to the type ‘part’ self link
Let’s say I include products into the shippings thus I will be able to see which products have been shipped in which quantity. The type part on the other hand is the underlying type of product and thus the self link of the product/part points to /parts/:id
"data": [
{
"type": "shippings",
"id": "5DDECEN",
"relationships": {
"products": {
"data": [
{
"type": "parts",
"id": "10PIQPD3"
},.......
"included": [
{
"type": "parts",
"id": "10PIQPD3",
"attributes": {
"partCondition": "F01",
"qtyShipped": 1
}, links: { self: '/parts/10PIQPD3' }
However if you follow the self link you will never see the shipped quantity within the parts resource object… is this an allowed behavior / design ?
What are better approaches ? If I just attach the shipped products as an array to attributes I will display type ‘parts’ with ids within the data.attributes which is not allowed as far as I understood. How to deal with such a behavior ?