loopbackio / loopbackio/loopback-next

Loopback 4: Exclude issue in hasone relations

Aperta
#7,517 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature help wanted OpenAPI
Lingua principale
TypeScript
Stelle
5.1k
Fork
1.1k
Merge medio
2g 21h
PR unite (30g)
27

Descrizione

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

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da getModelSchemaRef e dallo schema @requestBody mostrato nell’issue, concentrandoti su come vengono interpretati includeRelations ed exclude per le relazioni hasOne. Riproduci l’esempio con exclude: ['permissions']; è completato quando il campo della relazione annidata viene escluso senza modificare le esclusioni esistenti di primo livello.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.