loopbackio / loopbackio/loopback-next
@property.array doesn't work if nulls are allowed
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 5.1k
- Forks
- 1.1k
- Ø Merge
- 2 T. 21 Std.
- Gemergte PRs (30 T.)
- 27
Beschreibung
Describe the bug
Trying to make a model that maps to a nullable JSON or array column in PostgreSQL, so the entity property needs to permit nulls.
A property declared like this:
@property.array('string', {
required: false,
})
foo!: string[] | null;
Produces a @property.array can only decorate array properties from here: https://github.com/loopbackio/loopback-next/blob/a60ae8e43a1ec9d65929f19bbd364e332f28503b/packages/repository/src/decorators/model.decorator.ts#L155
Trying to "hack" it like this:
@property({
required: false,
type: Array,
itemType: 'string',
jsonSchema: {
type: 'array',
nullable: true,
items: { type: 'string' },
},
})
Results in incorrect data being sent to PostgreSQL (get JSON syntax errors because it's sending the object as an array to the PG driver instead of the JSON.stringify it should be using, because the array check in loopback-connector-postgresql (https://github.com/loopbackio/loopback-connector-postgresql/blob/61b5029275487fc7812d774ab4be16dc8aacd726/lib/postgresql.js#L788) fails
Logs
No response
Additional information
No response
Reproduction
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Lies packages/repository/src/decorators/model.decorator.ts bei der gemeldeten Prüfung der Array-Eigenschaft und vergleiche sie anschließend mit der Array-Verarbeitung in loopback-connector-postgresql/lib/postgresql.js. Reproduziere den Fall eines nullable Arrays mit der verlinkten CodeSandbox und überprüfe, dass der Decorator es akzeptiert und PostgreSQL gültiges JSON ohne Syntaxfehler erhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- postgresql, typescript
- Bereich
- backend, databases
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100