question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pagination does not work on related lists

See original GitHub issue

Description

I have a JSON API endpoint which returns an entity that has a related list property. I have this configured so that when I visit /api/entity it returns the top level entity without the associated values in the list. To get the related list of items the URL would be /api/entity/{entity-id}/items.

During startup I have configured the JsonApiDotNetCore library to have a default page size of 10 items. This works fine for top level entities, restricting the response collection to (in this case) ten items.

services.AddJsonApi(
                options =>
            {
                options.DefaultPageSize = 10;
...

I have a entity repository to configure the inclusion of items:

public class MyEntityRepository : DefaultEntityRepository<MyEntity, int>
    {
        public MyEntityRepository(
            ILoggerFactory loggerFactory,
            IJsonApiContext jsonApiContext,
            IDbContextResolver contextResolver,
            ResourceDefinition<MyEntity> resourceDefinition = null)
            : base(loggerFactory, jsonApiContext, contextResolver, resourceDefinition)
        {
        }

        public override IQueryable<MyEntity> Include(IQueryable<MyEntity> entities, string relationshipName)
        {
            if (relationshipName == "items")
            {
                return entities
                    .Include(o => o.Items);
            }

            return base.Include(entities, relationshipName);
        }
    }

But when I visit the /api/entity/{entity-id}/items endpoint, that default pagination has not been applied. Furthermore, if I add pagination as a query parameter, the whole collection is still returned /api/entity/1/items?page[size]=10&page[number]=2.

Is pagination at this level not supported? Is it likely I have not configured something? Or is this a bug?

Environment

  • JsonApiDotNetCore Version: 3.0.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredcnancecommented, Jan 30, 2019

Thanks for opening this. I don’t have time to address this right now, but in case someone else wants to start working on it, I believe the missing piece here is that this:

https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/f72e8ae2247b39fbf1bf5af446b27e9420cf01f4/src/JsonApiDotNetCore/Services/EntityResourceService.cs#L112

Needs to be done inside here:

https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/f72e8ae2247b39fbf1bf5af446b27e9420cf01f4/src/JsonApiDotNetCore/Services/EntityResourceService.cs#L131

We’ll have to think about how this will affect queries like /a?include=b&page[number]=2 since we need to ensure paging is only applied to the target resource of the query and currently the code path that performs includes is shared. It looks like we may need to restructure this path a bit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Related list record counts in pagination box are incorrect ...
This occurs whether you're in the tabbed view or scrollalicious view of a record. In each related list in a record, there is...
Read more >
Pagination in related list - Salesforce Developer Community
Hi All,. Any Idea of how to create pagination in custom related list.Here is my page and class. I need to display 5...
Read more >
List view pagination not working consistently
1.Try to create a new list in the site and check whether the pagination of this list works properly. · 2.Edit the number...
Read more >
Problem when trying to retrieve a list of records and ...
I'm facing a problem in a lot of my components lately, it's when I try to retrieve a list of records, and I...
Read more >
Pagination not working on list views · Issue #6298
Go to either Accounts / Opportunities / Contacts list view. Set Column Chooser to display/hide "User" or "Assigned To" column and save changes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found