Fix import of string values into array fields

This commit is contained in:
Andrew Kingston 2025-03-27 14:55:05 +00:00
parent 3870e0f01f
commit e0511f8b07
No known key found for this signature in database
1 changed files with 9 additions and 3 deletions

View File

@ -155,13 +155,19 @@ export async function importToRows(
schema.type === FieldType.ARRAY) &&
row[fieldName]
) {
const rowVal = Array.isArray(row[fieldName])
? row[fieldName]
: [row[fieldName]]
const isArray = Array.isArray(row[fieldName])
// Add option to inclusion constraints
const rowVal = isArray ? row[fieldName] : [row[fieldName]]
let merged = [...schema.constraints!.inclusion!, ...rowVal]
let superSet = new Set(merged)
schema.constraints!.inclusion = Array.from(superSet)
schema.constraints!.inclusion.sort()
// If array type, ensure we import the value as an array
if (!isArray && schema.type === FieldType.ARRAY) {
row[fieldName] = rowVal
}
}
}