loopbackio / loopbackio/loopback-next

Query nested relations recursively

Open
#5,080 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature Relations
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

## Suggestion

Original from [comment](https://github.com/strongloop/loopback-next/issues/3454#issuecomment-609847868).

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the custom-scope inclusion work in issue #3454 and the nested-relation filter examples in this issue. Define how a depth-limited traversal should behave for recursive Comment replies, then document the max-depth configuration and verify that traversal stops at either the limit or the end of the relation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.