loopbackio / loopbackio/loopback-next
Loopback 4: Exclude issue in hasone relations
Nobody has claimed this yet.
- 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?

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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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