loopbackio / loopbackio/loopback-next

Loopback 4: Exclude issue in hasone relations

Open
#7,517 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello all,

I have looked for a solution to that, but I see nothing in the documentation and in the forums. I start to think that it is not possible to do, or that it is some kind of issue.

In a schema, It is possible to exclude a field how comes from a @hasone relation?

![Captura de pantalla 2021-05-29 a las 10 00 18](https://user-images.githubusercontent.com/6785592/120094679-217fbb00-c122-11eb-8f11-0e39ca710521.png)

I have tried several things. The more weird is that if in the exclude you indicate a property who appears in the model A and in the hasOne relation model, in the schema, for both models, the property is excluded. :

```
@patch('/user/{id}', {
responses: {
'204': {
description: 'Update all the information related with the user',
},
},
})
@authenticate('jwt', { required: [PermissionKey.UpdateOwnUser] })
async updateById(
@param.path.string('id') id: string,
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(UserFeatures, {
includeRelations: true,
exclude: ['idUser', 'stripeCustomerId', 'userIAM.permissions'],
}),

},
},
})
```
The problem is that the exclude doesnt´work for the hasOne relation: exclude: ['idUser', 'stripeCustomerId'] --> OK exclude: ['permissions'] --> Fails

Any idea of how to exclude a field of the "hasOne Relation model"?

Thanks in advance

Best

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 at getModelSchemaRef and the @requestBody schema shown in the issue, focusing on how includeRelations and exclude are interpreted for hasOne relations. Reproduce the example with exclude: ['permissions']; done means the nested relation field is excluded without changing the existing top-level exclusions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
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.