Closed jgaehring closed 1 year ago
This still has some issues
Namely:
@mstenta or @paul121, any guess why a POST request to a an entity's relationship endpoint returns a 204
w/o updating that relationship?
Here's the example I tested locally, with a preexisting input log and quantity:
Here's the relevant JSON:API spec: https://jsonapi.org/format/#crud-updating-to-many-relationships
Log quantities are a bit unique because they have a revision ID as well. When you update an existing quantity then the log needs to be updated to that new revision as well. I haven't tried creating or updating log quantities via the relationship endpoint so there might be some gotchas there.
Some python code I have where I first create a quantity entity and then create/update a log in a second request. This is the part that specifies the quantity relationship & quantity revision ID:
# Add quantity to log.
log["relationships"]["quantity"] = {
"data": [
{
"type": "quantity--standard",
"id": harvest_quantity["data"]["id"],
"meta": {
"target_revision_id": harvest_quantity["data"]["attributes"]["drupal_internal__revision_id"]
}
},
]
}
Maybe this would work, assuming a quantityRevisionId
variable is populated:
const uri = '/api/log/input/f9f44a71-4373-4a60-ac36-37f5564b86e8/relationships/quantity';
const quantity = {
id: '9fb2963d-7185-4da7-9ccd-d6e29e0f22c1',
type: 'quantity--standard',
meta: {
target_revision_id: quantityRevisionId,
},
};
const data = JSON.stringify({ data: [quantity] });
return farm.remote.request(uri, { method: 'POST', data });
Oh that sounds like a good lead! Thanks, @paul121, I will try that out tomorrow.
This still has some issues, but I couldn't help committing some changes to the overall project structure along the way, which I'm too lazy to try and disentangle, so I just added some warnings instead.
This branches off #67 and should be merged subsequently.