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

Add the "relationships" prop in base included resources #239

Open
spersico opened this issue Oct 24, 2020 · 1 comment
Open

Add the "relationships" prop in base included resources #239

spersico opened this issue Oct 24, 2020 · 1 comment

Comments

@spersico
Copy link
Member

While testing localhost:3000/articles/1?include=author.votes

The included author in that same response, should also have the votes relationshipObjects in its "relationships" property:

{
    "data": {
        "id": 1,
        "type": "article",
        "attributes": {
            "body": "this is test 1",
            "voteCount": 2
        },
        "relationships": {
            "author": {
                "data": {
                    "id": 1,
                    "type": "user"
                }
            },
            "votes": {
                "data": [
                    {
                        "id": 1,
                        "type": "vote"
                    },
                    {
                        "id": 2,
                        "type": "vote"
                    }
                ]
            }
        }
    },
    "included": [
        {
            "id": 1,
            "type": "user",
            "attributes": {
                "username": "me",
                "email": "me@me.com",
                "createdAt": null,
                "updatedAt": null
            },
            "relationships": {
 // HERE THE VOTES RELATIONSHIP OBJECTS SHOULD ALSO APPEAR!
// JUST LIKE IN THE ARTICLE (id & type)
}
        },
        {
            "id": 1,
            "type": "vote",
            "attributes": { ... },
            "relationships": {
                "user": {
                    "data": {
                        "id": 1,
                        "type": "user"
                    }
                },
                "article": {
                    "data": {
                        "id": 1,
                        "type": "article"
                    }
                }
            }
        },
        {
            "id": 2,
            "type": "vote",
            "attributes": {... },
            "relationships": {
                "user": {
                    "data": {
                        "id": 1,
                        "type": "user"
                    }
                },
                "article": {
                    "data": {
                        "id": 1,
                        "type": "article"
                    }
                }
            }
        }
    ]
}

Originally posted by @spersico in #227 (comment)

@spersico
Copy link
Member Author

spersico commented Oct 24, 2020

An extra info: this only happens when the base included resource (in this case, the user) and the nested relationship has a one-to-many relationship with the nested resource.
For example, when querying localhost:3000/user/1?include=votes.article in the test-app, the base resources have all the relationships (see the included vote resource):

{
    "data": {
        "id": 1,
        "type": "user",
        "attributes": {
            "username": "me",
            "email": "me@me.com",
            "friends": [
                {
                    "name": "Joel"
                },
                {
                    "name": "Ryan"
                }
            ],
            "coolFactor": 3,
            "roles": [
                "user",
                "author",
                "voter"
            ]
        },
        "relationships": {
            "votes": {
                "data": [
                    {
                        "id": 1,
                        "type": "vote"
                    },
                    {
                        "id": 2,
                        "type": "vote"
                    }
                ]
            }
        }
    },
    "included": [
        {
            "id": 1,
            "type": "vote",
            "attributes": {
                "points": 10,
                "createdOn": null,
                "updatedOn": null,
                "updatedBy": null,
                "createdBy": null
            },
            "relationships": {
                "user": {
                    "data": {
                        "id": 1,
                        "type": "user"
                    }
                },
                "article": {
                    "data": {
                        "id": 1,
                        "type": "article"
                    }
                }
            }
        },
         ....
    ]
}

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

No branches or pull requests

1 participant