json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Nested Resource foreign key parsed as string

Open jasonlimantoro opened this issue 5 years ago • 7 comments

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

jasonlimantoro avatar Mar 02 '19 04:03 jasonlimantoro

Can this one be merged? We suffer from the same problem!

wilgert avatar Aug 15 '19 09:08 wilgert

Same here. It's kind of a blocker when you are trying to mock POST methods.

STotev avatar Oct 29 '19 11:10 STotev

Hoping this could get merged as well!

underGhost avatar Apr 10 '20 04:04 underGhost

Would be great if we could get this merged.

iluvmemes avatar Oct 14 '20 11:10 iluvmemes

Any update on this?

mancioshell avatar Nov 21 '21 11:11 mancioshell

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 .

arig2a avatar Nov 22 '21 22:11 arig2a

any update with this?

skitband avatar Oct 04 '22 03:10 skitband

@typicode three years are passed and this issue is still not fixed :( . Can you merg this?

Polkasa avatar Dec 13 '22 12:12 Polkasa