Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

EmilMoe's avatar
Level 10

Require item in API even when not on the paging

My problem is when paging my API requests it happens rather often that an object which has a reference to another is intersected.

For example I call api/books/1 on that page I already loaded api/authors. But the author associated to Book:1 isn't in on the first authors page, maybe it indexes 10 per page and this is Author:20.

Now my selects and lists cannot properly display it as they cause a mismatch where the author isn't in the list.

My question is how this is best solved? I have played with some parameters such as &include=20 to force an extra added, but I feel it's bad design and then users could index everything by running many include queries.

0 likes
3 replies
bobbybouwmann's avatar

I don't 100% understand your problem, but it sounds to me that you always need to include the author on the book response. This way you can match it with your authors list that you already fetched. If it doesn't exist in there you can grab it from the book response and add it to the list.

Does that make sense?

1 like
EmilMoe's avatar
Level 10

Yes I guess you are right that should be the most optimal solution.

Please or to participate in this conversation.