loopback-next
loopback-next copied to clipboard
@property.array doesn't work if nulls are allowed
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
https://codesandbox.io/s/zen-thompson-keo2is