Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer arrays are not working properly #53

Open
lok52 opened this issue Mar 14, 2024 · 1 comment
Open

Integer arrays are not working properly #53

lok52 opened this issue Mar 14, 2024 · 1 comment

Comments

@lok52
Copy link

lok52 commented Mar 14, 2024

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));
@Mirasaki
Copy link

Would love to see a fix for this, as any model with Type[] or JSONB arrays are no longer editable through the dashboard. All update requests send NaN for any Int[] fields that we're commonly using in our schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants