loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

Query nested relations recursively

Open agnes512 opened this issue 4 years ago • 5 comments

Suggestion

Original from comment.

LoopBack 4 provides the custom scope to achieve inclusion, which was implemented in #3454. But it only goes down to the certain levels of relations that are described in the filter, for example, three levels:

    const filter = {
      include: [
        {
          relation: 'nested 1',
          scope: {
            include: [{relation: 'nested 2'}],
          },
        },
      ],
    };

It'd be good to have a better way to query nested relations to max depth/ N degrees, something like {relation: "nested", depth: 10}.

Examples

Model Comment has many replies: Comment[], and comments in the replies has many replies, etc. Returns when there is no more replies or the max depth is reached.

Acceptance criteria

  • [ ] Provide a way to query nested relations to max depth/ N degrees, or at least to have a helper function for writing the filter.
  • [ ] Should document how to configure the max depth of such traverses.

agnes512 avatar Apr 09 '20 20:04 agnes512

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

stale[bot] avatar Dec 25 '20 14:12 stale[bot]

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

stale[bot] avatar Jul 14 '21 12:07 stale[bot]

Is there any update about this issue ?

talhakca avatar Dec 08 '21 12:12 talhakca

No updates at the moment.

achrinza avatar Dec 08 '21 14:12 achrinza

hey All,

we are doing a research using TypeORM and loopback 4 but there are a couple of issues on models. Eg how to setup relations manyToOne.

Do you have any ideo how to hooks repositories to avoid to use N+1 query? there are too many connection to the database. lb3 https://loopback.io/doc/en/lb3/Nested-queries.html

Maybe use include as another ORM could help to avoid and scale more application.

A quick solution for us is use custom query but I am not sure if that could be the best solution. Also, we are going to use elastic search in our API.

My second approach is create a handler in all my request and make queries then map that result in the repositories.

mauricioA0 avatar May 11 '22 14:05 mauricioA0