Description
I'm unsure if the feature I'm describing here is not implemented, or if I am just not configuring things correctly to make it work this way.
If I have a Post
model which HasMany
Comment
models, and I include=comments
when requesting from /api/v1/posts/1
, I see something like this (note 15 comments):
{
"jsonapi": {
"version": "1.0"
},
"links": {
"self": "https://localhost/api/v1/posts/1"
},
"data": {
"type": "posts",
"id": "1",
"attributes": {
"id": "1",
"name": "Post 56759",
"uuid": "1243f3d6-3e2d-4ee7-b58d-20055d3b9d2b",
"created_at": "2022-03-21T12:00:04.000000Z",
"updated_at": "2022-03-21T12:00:04.000000Z",
"is_new": false
},
"relationships": {
"comments": {
"links": {
"related": "https://localhost/api/v1/posts/1/comments",
"self": "https://localhost/api/v1/posts/1/relationships/comments",
},
"data": [
{
"type": "comments",
"id": "1"
},
{
"type": "comments",
"id": "2"
},
{
"type": "comments",
"id": "3"
},
{
"type": "comments",
"id": "4"
},
{
"type": "comments",
"id": "5"
},
{
"type": "comments",
"id": "6"
},
{
"type": "comments",
"id": "7"
},
{
"type": "comments",
"id": "8"
},
{
"type": "comments",
"id": "9"
},
{
"type": "comments",
"id": "10"
},
{
"type": "comments",
"id": "11"
},
{
"type": "comments",
"id": "12"
},
{
"type": "comments",
"id": "13"
},
{
"type": "comments",
"id": "14"
},
{
"type": "comments",
"id": "15"
}
]
}
},
"links": {
"self": "https://localhost/api/v1/posts/1"
}
},
"included": [
// ...
]
}
But I'd prefer to be able to see something like this (note 5 included Comment models, and additional relationships.comments.links
and relationships.comments.meta
fields showing the pagination options):
{
"jsonapi": {
"version": "1.0"
},
"links": {
"self": "https://localhost/api/v1/posts/1"
},
"data": {
"type": "posts",
"id": "1",
"attributes": {
"id": "1",
"name": "Post 56759",
"uuid": "1243f3d6-3e2d-4ee7-b58d-20055d3b9d2b",
"created_at": "2022-03-21T12:00:04.000000Z",
"updated_at": "2022-03-21T12:00:04.000000Z",
"is_new": false
},
"relationships": {
"comments": {
"links": {
"related": "https://localhost/api/v1/posts/1/comments",
"self": "https://localhost/api/v1/posts/1/relationships/comments",
"first": "https://localhost/api/v1/posts/1/comments?page%5Bnumber%5D=1&page%5Bsize%5D=5",
"last": "https://localhost/api/v1/posts/1/comments?page%5Bnumber%5D=3&page%5Bsize%5D=5",
"next": "https://localhost/api/v1/posts/1/comments?page%5Bnumber%5D=2&page%5Bsize%5D=5",
},
"meta": {
"page": {
"currentPage": 1,
"from": 1,
"lastPage": 3,
"perPage": 5,
"to": 5,
"total": 15
}
},
"data": [
{
"type": "comments",
"id": "1"
},
{
"type": "comments",
"id": "2"
},
{
"type": "comments",
"id": "3"
},
{
"type": "comments",
"id": "4"
},
{
"type": "comments",
"id": "5"
}
]
}
},
"links": {
"self": "https://localhost/api/v1/posts/1"
}
},
"included": [
// ...
]
}
This would mean fetching a collection of 15 Post
models with potentially many Comment
models each still only returns a maximum of 75 Comment
models in the compound document (15 Post
models × max 5 Comment
models each).
My reading of the spec leads me to believe this is possible within the constraints of the specification, but I'm not sure if/how this package supports it.