This commit is contained in:
Adria Navarro 2023-10-05 16:29:27 +02:00
parent 7ee63365f7
commit ea86ded912
4 changed files with 23 additions and 23 deletions

View File

@ -6,13 +6,9 @@ import isEqual from "lodash/isEqual"
import uniq from "lodash/uniq" import uniq from "lodash/uniq"
import { updateAllFormulasInTable } from "../row/staticFormula" import { updateAllFormulasInTable } from "../row/staticFormula"
import { context } from "@budibase/backend-core" import { context } from "@budibase/backend-core"
import { import { FieldSchema, FormulaFieldMetadata, Table } from "@budibase/types"
FieldSchema,
FormulaFieldMetadata,
RelationshipFieldMetadata,
Table,
} from "@budibase/types"
import sdk from "../../../sdk" import sdk from "../../../sdk"
import { isRelationshipColumn } from "../../../db/utils"
function isStaticFormula( function isStaticFormula(
column: FieldSchema column: FieldSchema
@ -104,10 +100,6 @@ async function checkIfFormulaNeedsCleared(
} }
} }
function isLink(column: FieldSchema): column is RelationshipFieldMetadata {
return column.type === FieldTypes.LINK
}
/** /**
* This function adds a note to related tables that they are * This function adds a note to related tables that they are
* used in a static formula - so that the link controller * used in a static formula - so that the link controller
@ -127,7 +119,9 @@ async function updateRelatedFormulaLinksOnTables(
// clone the tables, so we can compare at end // clone the tables, so we can compare at end
const initialTables = cloneDeep(tables) const initialTables = cloneDeep(tables)
// first find the related column names // first find the related column names
const relatedColumns = Object.values(table.schema).filter(isLink) const relatedColumns = Object.values(table.schema).filter(
isRelationshipColumn
)
// we start by removing the formula field from all tables // we start by removing the formula field from all tables
for (let otherTable of tables) { for (let otherTable of tables) {
if (!otherTable.relatedFormula) { if (!otherTable.relatedFormula) {

View File

@ -1,13 +1,9 @@
import { ViewName, getQueryIndex } from "../utils" import { ViewName, getQueryIndex, isRelationshipColumn } from "../utils"
import { FieldTypes } from "../../constants" import { FieldTypes } from "../../constants"
import { createLinkView } from "../views/staticViews" import { createLinkView } from "../views/staticViews"
import { context, logging } from "@budibase/backend-core" import { context, logging } from "@budibase/backend-core"
import { import { LinkDocument, LinkDocumentValue, Table } from "@budibase/types"
FieldSchema,
LinkDocument,
LinkDocumentValue,
Table,
} from "@budibase/types"
export { createLinkView } from "../views/staticViews" export { createLinkView } from "../views/staticViews"
/** /**
@ -93,7 +89,7 @@ export function getUniqueByProp(array: any[], prop: string) {
export function getLinkedTableIDs(table: Table) { export function getLinkedTableIDs(table: Table) {
return Object.values(table.schema) return Object.values(table.schema)
.filter((column: FieldSchema) => column.type === FieldTypes.LINK) .filter(isRelationshipColumn)
.map(column => column.tableId) .map(column => column.tableId)
} }
@ -114,7 +110,7 @@ export function getRelatedTableForField(table: Table, fieldName: string) {
// look to see if its on the table, straight in the schema // look to see if its on the table, straight in the schema
const field = table.schema[fieldName] const field = table.schema[fieldName]
if (field != null) { if (field != null) {
return field.tableId return (field as any).tableId
} }
for (let column of Object.values(table.schema)) { for (let column of Object.values(table.schema)) {
if (column.type === FieldTypes.LINK && column.fieldName === fieldName) { if (column.type === FieldTypes.LINK && column.fieldName === fieldName) {

View File

@ -1,6 +1,12 @@
import newid from "./newid" import newid from "./newid"
import { db as dbCore } from "@budibase/backend-core" import { db as dbCore } from "@budibase/backend-core"
import { DocumentType, VirtualDocumentType } from "@budibase/types" import {
DocumentType,
FieldSchema,
RelationshipFieldMetadata,
VirtualDocumentType,
} from "@budibase/types"
import { FieldTypes } from "src/constants"
export { DocumentType, VirtualDocumentType } from "@budibase/types" export { DocumentType, VirtualDocumentType } from "@budibase/types"
type Optional = string | null type Optional = string | null
@ -307,3 +313,9 @@ export function extractViewInfoFromID(viewId: string) {
tableId: res!.groups!["tableId"], tableId: res!.groups!["tableId"],
} }
} }
export function isRelationshipColumn(
column: FieldSchema
): column is RelationshipFieldMetadata {
return column.type === FieldTypes.LINK
}

View File

@ -1,11 +1,9 @@
import { import {
AutoReason, AutoReason,
Datasource, Datasource,
FieldSchema,
FieldType, FieldType,
RelationshipType, RelationshipType,
} from "@budibase/types" } from "@budibase/types"
import { FieldTypes } from "../../../constants"
function checkForeignKeysAreAutoColumns(datasource: Datasource) { function checkForeignKeysAreAutoColumns(datasource: Datasource) {
if (!datasource.entities) { if (!datasource.entities) {