# Paginating Relationships / Includes?

**URL:** <https://discuss.jsonapi.org/t/paginating-relationships-includes/820>\
**Category:** Uncategorized\
**Created:** [October 28, 2016, 4:33pm UTC](https://discuss.jsonapi.org/t/paginating-relationships-includes/820 "2016-10-28T16:33:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KernelCurry](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/kernelcurry/32/341_2.png) [@KernelCurry](https://discuss.jsonapi.org/u/KernelCurry)\
**Post date:** [October 28, 2016, 4:33pm UTC](https://discuss.jsonapi.org/t/paginating-relationships-includes/820/1 "2016-10-28T16:33:11Z")

</div>

If you had a `article` and you included `comments`, all of the comments would be returned in the response.

Now lets say that this `article` has 100,000 `comments` associated to it. If we returned all 100,000 `comments` in one request, the server might timeout or the amount data may be too large.

In this case, is there a way to paginate the number of `comments` in the relationships/included array?.. should we not allow for includes? … is there something that I have not thought of?

---

<div class="post-metadata">

**Author:** ![hlubovac](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/hlubovac/32/385_2.png) [@hlubovac](https://discuss.jsonapi.org/u/hlubovac)\
**Post date:** [March 10, 2017, 10:20pm UTC](https://discuss.jsonapi.org/t/paginating-relationships-includes/820/2 "2017-03-10T22:20:36Z")

</div>

Did you ever get an answer for this? What did you decide to do?

The only thing the relevant section of specs ([http://jsonapi.org/format/#fetching-pagination](http://jsonapi.org/format/#fetching-pagination)) says is this:

“Pagination links MUST appear in the links object that corresponds to a collection. To paginate the primary data, supply pagination links in the top-level links object. **To paginate an included collection returned in a compound document, supply pagination links in the corresponding links object.** ”

My problem is understanding what exactly is the **links** object that **corresponds** to items in the **included** section - since that section is an array, I don’t see where that **links** object would even go.

---

<div class="post-metadata">

**Author:** ![KernelCurry](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/kernelcurry/32/341_2.png) [@KernelCurry](https://discuss.jsonapi.org/u/KernelCurry)\
**Post date:** [March 11, 2017, 7:25pm UTC](https://discuss.jsonapi.org/t/paginating-relationships-includes/820/3 "2017-03-11T19:25:40Z")

</div>

TLDR;  
We did not implement includes.

After theory-crafting out scaling issues, it became apparent we would need to paginate includes if we returned them… BUT we would also want to have a mechanism for allowing to specify what “page” we are paginating each includes on and return them properly. This was a pain in the … well you know. It also came to our attention that if we did paginate the includes, some partners may assume the includes we would returning are all of them, not just a subset.

Because the spec does no specify how to do this completely, we decided not to implement includes. (includes are not required for spec as far as I can tell). This does mean partners must make more requests. But the up side: we can limit the number of queries per request to a manageable number and keep response times sub 100ms.

---

<div class="post-metadata">

**Author:** ![Jerry87](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/jerry87/32/887_2.png) [@Jerry87](https://discuss.jsonapi.org/u/Jerry87)\
**Post date:** [July 21, 2024, 8:06am UTC](https://discuss.jsonapi.org/t/paginating-relationships-includes/820/4 "2024-07-21T08:06:46Z")

</div>

> My problem is understanding what exactly is the **links** object that **corresponds** to items in the **included** section - since that section is an array, I don’t see where that **links** object would even go.

Did you ever get an answer for this?  
Because I have the same issue understanding where exactly to put pagination links for included collections.

> [@Where to put pagination links for included collections](https://discuss.jsonapi.org/t/where-to-put-pagination-links-for-included-collections/2885):
>
> Regarding pagination links, the specification says: Pagination links MUST appear in the links object that corresponds to a collection. To paginate the primary data, supply pagination links in the top-level links object. To paginate an included collection returned in a compound document, supply pagination links in the corresponding links object. But I´m confused about the included-collection part. What does “corresponding” refer to? Does it refer to the links object of the relationship object…

I know it´s more than seven years ago, but helpful answers are always appreciated 🙂
