loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.07k forks source link

Query nested relations recursively #5080

Open agnes512 opened 4 years ago

agnes512 commented 4 years ago

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

stale[bot] commented 3 years ago

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] commented 3 years ago

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.

talhakca commented 2 years ago

Is there any update about this issue ?

achrinza commented 2 years ago

No updates at the moment.

mauricioA0 commented 2 years ago

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.