Fixing some issues with multi-select coming back as string.
This commit is contained in:
parent
0e499fd60d
commit
2312defd3c
|
@ -163,8 +163,8 @@ module External {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function basicProcessing(row: Row, table: Table) {
|
function basicProcessing(row: Row, table: Table): Row {
|
||||||
const thisRow: { [key: string]: any } = {}
|
const thisRow: Row = {}
|
||||||
// filter the row down to what is actually the row (not joined)
|
// filter the row down to what is actually the row (not joined)
|
||||||
for (let fieldName of Object.keys(table.schema)) {
|
for (let fieldName of Object.keys(table.schema)) {
|
||||||
const value = row[`${table.name}.${fieldName}`] || row[fieldName]
|
const value = row[`${table.name}.${fieldName}`] || row[fieldName]
|
||||||
|
@ -179,6 +179,20 @@ module External {
|
||||||
return thisRow
|
return thisRow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fixArrayTypes(row: Row, table: Table) {
|
||||||
|
for (let [fieldName, schema] of Object.entries(table.schema)) {
|
||||||
|
if (schema.type === FieldTypes.ARRAY && typeof row[fieldName] === "string") {
|
||||||
|
try {
|
||||||
|
row[fieldName] = JSON.parse(row[fieldName])
|
||||||
|
} catch (err) {
|
||||||
|
// couldn't convert back to array, ignore
|
||||||
|
delete row[fieldName]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return row
|
||||||
|
}
|
||||||
|
|
||||||
function isMany(field: FieldSchema) {
|
function isMany(field: FieldSchema) {
|
||||||
return (
|
return (
|
||||||
field.relationshipType && field.relationshipType.split("-")[0] === "many"
|
field.relationshipType && field.relationshipType.split("-")[0] === "many"
|
||||||
|
@ -358,7 +372,10 @@ module External {
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const thisRow = basicProcessing(row, table)
|
const thisRow = fixArrayTypes(basicProcessing(row, table), table)
|
||||||
|
if (thisRow._id == null) {
|
||||||
|
throw "Unable to generate row ID for SQL rows"
|
||||||
|
}
|
||||||
finalRows[thisRow._id] = thisRow
|
finalRows[thisRow._id] = thisRow
|
||||||
// do this at end once its been added to the final rows
|
// do this at end once its been added to the final rows
|
||||||
finalRows = this.updateRelationshipColumns(
|
finalRows = this.updateRelationshipColumns(
|
||||||
|
|
Loading…
Reference in New Issue