Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep parent resource id as int instead of str for nested post #951

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Praseetha-KR
Copy link

Current behaviour:

POST on nested resources creates a resource with parent resource id value as string.

eg:

POST /posts/1/comments
{
    "body": "some comment"
}
---
{
    "body": "some comment",
    "createdAt": 1555443321417,
    "postId": "1", // <string>
    "id": 1
}

_embed doesn't pick up resources where corresponding parent resource id is string:

GET /posts/1?_embed=comments
---
{
    "id": 1,
    "title": "json-server", 
    "author": "typicode",
    "comments": [] // empty!!!
}

Behaviour after the fix:

This PR casts the parent resource id to int on nested resource POST request body.

POST /posts/1/comments
{
    "body": "some comment"
}
---
{
    "body": "some comment",
    "createdAt": 1555443321417,
    "postId": 1, // <int>
    "id": 1
}

Which in turn fixes _embed's response:

GET /posts/1?_embed=comments
---
{
    "id": 1,
    "title": "json-server", 
    "author": "typicode",
    "comments": [ // not empty
        {
            "body": "some comment",
            "createdAt": 1555443321417,
            "postId": 1,
            "id": 1
        }
    ]
}

@b4dnewz
Copy link

b4dnewz commented Aug 24, 2019

Also addressed in #931 with correct handling of string ids

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants