Fixing an issue with creating relationships between existing tables, not using the correct type for the primary key in the foreign key relationship.
This commit is contained in:
parent
401d64b074
commit
1aca5d6407
|
@ -391,8 +391,9 @@ export class ExternalRequest {
|
|||
}
|
||||
}
|
||||
relatedRow = processFormulas(linkedTable, relatedRow)
|
||||
const relatedDisplay = display ? relatedRow[display] : undefined
|
||||
row[relationship.column][key] = {
|
||||
primaryDisplay: display ? relatedRow[display] : undefined,
|
||||
primaryDisplay: relatedDisplay || "Invalid display column",
|
||||
_id: relatedRow._id,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,10 +79,17 @@ function generateSchema(
|
|||
if (!relatedTable) {
|
||||
throw "Referenced table doesn't exist"
|
||||
}
|
||||
schema.integer(column.foreignKey).unsigned()
|
||||
const relatedPrimary = relatedTable.primary[0]
|
||||
const externalType = relatedTable.schema[relatedPrimary].externalType
|
||||
if (externalType) {
|
||||
schema.specificType(column.foreignKey, externalType)
|
||||
} else {
|
||||
schema.integer(column.foreignKey).unsigned()
|
||||
}
|
||||
|
||||
schema
|
||||
.foreign(column.foreignKey)
|
||||
.references(`${tableName}.${relatedTable.primary[0]}`)
|
||||
.references(`${tableName}.${relatedPrimary}`)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import {
|
||||
FieldTypes,
|
||||
FormulaTypes,
|
||||
AutoFieldDefaultNames,
|
||||
AutoFieldSubTypes,
|
||||
FieldTypes,
|
||||
FormulaTypes,
|
||||
} from "../../constants"
|
||||
import { processStringSync } from "@budibase/string-templates"
|
||||
import { FieldSchema, Table, Row } from "@budibase/types"
|
||||
import { FieldSchema, FieldType, Row, Table } from "@budibase/types"
|
||||
|
||||
/**
|
||||
* If the subtype has been lost for any reason this works out what
|
||||
|
@ -50,6 +50,7 @@ export function processFormulas(
|
|||
const isStatic = schema.formulaType === FormulaTypes.STATIC
|
||||
if (
|
||||
schema.type !== FieldTypes.FORMULA ||
|
||||
schema.formula == null ||
|
||||
(dynamic && isStatic) ||
|
||||
(!dynamic && !isStatic)
|
||||
) {
|
||||
|
@ -57,13 +58,11 @@ export function processFormulas(
|
|||
}
|
||||
// iterate through rows and process formula
|
||||
for (let i = 0; i < rowArray.length; i++) {
|
||||
if (schema.formula) {
|
||||
let row = rowArray[i]
|
||||
let context = contextRows ? contextRows[i] : row
|
||||
rowArray[i] = {
|
||||
...row,
|
||||
[column]: processStringSync(schema.formula, context),
|
||||
}
|
||||
let row = rowArray[i]
|
||||
let context = contextRows ? contextRows[i] : row
|
||||
rowArray[i] = {
|
||||
...row,
|
||||
[column]: processStringSync(schema.formula, context),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue