Relationship with thousands of records

Hello buddies.
Sorry if I duplicate the topic but I met some misunderstanding during I prepare my relationships in JSON:API topology of response.

I have a lot of records in relation. For an example thousands.

let’s imagine some article has 10000 comments. It means that we have to show all of them in within the array:
“comments”: {
“links”: {
“related”: “{url}/4/comments”,
“self”: “{url}/4/relationships/comments”
“data”: [
“type”: “comment”,
“id”: “10”
“type”: “comment”,
“id”: “12”


I thought a lot about this situation and only one decision I got:

  • setup query string param ?include=comments&page[comments.number]=20

These are so raw examples, just to get what I mean.

I just was thinking about the same problem.

But why would you call it &page[comments.number]=20, with .number?

I was thinking applying the pagination as well?

if param “page” is number => just the main resource

if param “page” is array => pass it down to relationships

And actually in the specification its written:
A relationship object that represents a to-many relationship MAY also contain pagination links under the links member, as described below. Any pagination links in a relationship object MUST paginate the relationship data, not the related resources.

So you have the pagination-information inside the relationships:

{ type: article
  relationships: {
     comments: {
          data: [ {type: comments, id: 3}, {type: comments, id: 4},  ]
          links: [ first, last, prev, next ],
          meta: [ current_page: 2, per_page: 2, last_page: 10 ]
  includes: {
       {type: comments, id: 3},
       {type: comments, id: 4},

In includes you are just including the objects, which are inside the relationships.


This is an over complicated solution for a simple problem.

If a relationship has the potential to have a lot of records, just avoid adding the data member.

If a client wants to retrieve the records, they can simply call /articles/id/comments and use whatever simple pagination strategy is used by the API.

@SpirIT You are misinterpreting the quote. The links with pagination should point to something like /articles/id/comments?page[number]=1&page[size]=10, definitely not /articles?page[comments]=1.