Skip to content

Integer arrays are not working properly #53

@lok52

Description

@lok52

convertParam function doesn't handle arrays. When it converts an integer array property (prisma type is Int[]) it tries to parse it as a Number and it leads to undefined behaviour. I believe to fix that you need to override isArray method in the Property class and adjust convertParam accordingly.

export const convertParam = (
property: Property,
fields: DMMF.Model['fields'],
value: string | boolean | number | Record<string, any> | null | undefined,
): string | boolean | number | Record<string, any> | null | undefined => {
const type = property.type();
if (type === 'mixed') return value;
if (type === 'number') {
return safeParseNumber(value);
}
if (type === 'reference') {
const foreignColumn = fields.find((field) => field.name === property.foreignColumnName());
if (!foreignColumn) return value;
if (value === undefined || value === null) return value;
const foreignColumnType = foreignColumn.type;
if (foreignColumnType === 'String') return String(value);
return safeParseNumber(value);
}
return value;
};

As a temporary fix I have to patch convertParam with something like this:

if (Array.isArray(value)) return value.map((v) => convertParam(property, fields, v));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions