loopbackio / loopbackio/loopback-next

Setting a foreign key as a nullable key in model file is not working in loopback 4

Offen
#8,957 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

Describe the bug

I want to set up a field that is defined as a foreign key, but also supports the ability to be null. In the model file, I have this already

  @belongsTo(() => Bill, { keyTo: 'BillID', name: 'Bill' })
  BillID: Number;

But what I want to do is something like this

  @property({
    type: Number,
    required: false,
    jsonSchema: { nullable: true },
    mssql: { "columnName": "BillID", "dataType": "int", "dataPrecision": null, "dataScale": null, "nullable": "YES" },
  })
  @belongsTo(() => Bill, { keyTo: 'BillID', name: 'Bill' })
  BillID: Number;

but that does not work. How can I set this up?

Logs

No response

Additional information

No response

Reproduction

not needed as problem is obvious

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

Das Issue identifiziert eine Modelldatei, die die Deklarationen @property und @belongsTo für BillID enthält; beginne damit nachzuverfolgen, wie LoopBack 4 nullable Fremdschlüssel darstellt. Als erledigt gilt die Aufgabe, wenn eine unterstützte Konfiguration bestätigt oder eine erforderliche Änderung am Framework geklärt wurde und das Verhalten von BillID bei nullable Werten verifiziert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
nodejs, typescript
Bereich
api, backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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