json-server
json-server copied to clipboard
Nested Resource foreign key parsed as string
When doing a POST
request to create a new nested resource, its foreign key is parsed as string, as opposed to integer. This causes the parent to not recognize its child resource.
For example
POST /posts/1/images
BODY
{
url: ‘some-url’
}
would yield a response
{
url: ‘some-url’,
postId: “1”,
id: 1
}
So, when doing a GET request
GET /posts/1?_embed=images
, the response is as follows
{
id: 1,
...,
images : [],
}
Essentially, the post doesn’t recognize the image attached to it, because the foreign key is parsed as string.
Manually changing the foreign key into integer data type will work.
Any suggestion? Is this how it’s supposed to work?
Some existing comments that I found
- https://github.com/typicode/json-server/issues/396#issuecomment-345611712
- https://github.com/typicode/json-server/issues/24#issuecomment-357125108
Can this one be merged? We suffer from the same problem!
Same here. It's kind of a blocker when you are trying to mock POST methods.
Hoping this could get merged as well!
Would be great if we could get this merged.
Any update on this?
No....
Le dim. 21 nov. 2021 à 12:03 PM, Alessandro Mancini < @.***> a écrit :
Any update on this?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/typicode/json-server/issues/925#issuecomment-974795202, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATW2M4WFJWDNJVMZFSJ67SDUNDGYJANCNFSM4G3IWOCA .
any update with this?
@typicode three years are passed and this issue is still not fixed :( . Can you merg this?