-
-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug*
When serializing a complex object with defined relationships, all related fields are included in the attributes by default as well as in relationships.
To avoid this, you currently have to explicitly define a projection that excludes the relationship fields which adds an unnecessary overhead.
To Reproduce*
See replit: https://replit.com/@egmacke/ts-japi-issue-76
Result is
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "User",
"id": "1",
"attributes": {
"name": "Foo",
"articles": [
{
"id": "1",
"title": "Article 1",
"body": "Article 1 body"
},
{
"id": "2",
"title": "Article 2",
"body": "Article 2 body"
}
]
},
"relationships": {
"articles": {
"data": [
{
"type": "Article",
"id": "1"
},
{
"type": "Article",
"id": "2"
}
]
}
}
}
}
I would expect the result to be (which can be achieved using the serializer option {projection: {articles: 0}})
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "User",
"id": "1",
"attributes": {
"name": "Foo",
},
"relationships": {
"articles": {
"data": [
{
"type": "Article",
"id": "1"
},
{
"type": "Article",
"id": "2"
}
]
}
}
}
}
Expected behavior*
When a relator is defined for a given field, it should be automatically excluded from the serialized attributes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working