loopbackio / loopbackio/loopback-next

belongsTo relation lookup fails when fields parameter omits id

Open
#8,261 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

When combining an include parameter with a fields parameter which omits id, the belongsTo relation lookup fails.

Consider the following example, where we find Todo entities with their respective TodoList's titles.

todoRepository.find({include: [{relation: 'todoList', scope: {fields: ['title']}}]});

The returned Todo entities will be missing their respective TodoLists.

Logs

No response

Additional information

No response

Reproduction

https://github.com/tdeignan1/loopback-next/tree/demo/include-with-fields-bug

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 with the repository find call shown in the issue and trace how the belongsTo include is resolved when the related scope fields contain only title. Use the linked reproduction to confirm the failure, and consider the work done when the Todo entities include their TodoList despite the omitted id.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.