1
0
Fork 0
mirror of synced 2024-10-04 03:54:37 +13:00

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:
mike12345567 2023-04-19 17:17:37 +01:00
parent 401d64b074
commit 1aca5d6407
3 changed files with 20 additions and 13 deletions

View file

@ -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,
}
}

View file

@ -79,10 +79,17 @@ function generateSchema(
if (!relatedTable) {
throw "Referenced table doesn't exist"
}
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
}

View file

@ -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,7 +58,6 @@ 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] = {
@ -66,7 +66,6 @@ export function processFormulas(
}
}
}
}
return single ? rowArray[0] : rowArray
}