loopbackio / loopbackio/loopback-next

Loopback 4: Exclude issue in hasone relations

Offen
#7,517 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature help wanted OpenAPI
Vorherrschende Sprache
TypeScript
Sterne
5.1k
Forks
1.1k
Ø Merge
2 T. 21 Std.
Gemergte PRs (30 T.)
27

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei getModelSchemaRef und dem im Issue gezeigten @requestBody-Schema und konzentriere dich darauf, wie includeRelations und exclude für hasOne-Relationen interpretiert werden. Reproduziere das Beispiel mit exclude: ['permissions']; fertig ist es, wenn das Feld der verschachtelten Relation ausgeschlossen wird, ohne die bestehenden Ausschlüsse auf oberster Ebene zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
api
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.