Fixing issue with SQL tables and using formulas that contain relationships as display columns. Also cleaning up imports in ExternalRequests a bit.

This commit is contained in:
mike12345567 2023-04-19 16:16:22 +01:00
parent dc3d0e5e98
commit 401d64b074
1 changed files with 20 additions and 12 deletions

View File

@ -1,31 +1,32 @@
import { import {
Datasource,
FieldSchema,
FieldType,
FilterType, FilterType,
IncludeRelationship, IncludeRelationship,
Operation, Operation,
PaginationJson, PaginationJson,
RelationshipsJson, RelationshipsJson,
RelationshipTypes,
Row,
SearchFilters, SearchFilters,
SortJson, SortJson,
Datasource,
FieldSchema,
Row,
Table,
RelationshipTypes,
FieldType,
SortType, SortType,
Table,
} from "@budibase/types" } from "@budibase/types"
import { import {
breakExternalTableId,
breakRowIdField, breakRowIdField,
convertRowId,
generateRowIdField, generateRowIdField,
isRowId, isRowId,
convertRowId, isSQL,
} from "../../../integrations/utils" } from "../../../integrations/utils"
import { getDatasourceAndQuery } from "./utils" import { getDatasourceAndQuery } from "./utils"
import { FieldTypes } from "../../../constants" import { FieldTypes } from "../../../constants"
import { breakExternalTableId, isSQL } from "../../../integrations/utils"
import { processObjectSync } from "@budibase/string-templates" import { processObjectSync } from "@budibase/string-templates"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { processFormulas, processDates } from "../../../utilities/rowProcessor" import { processDates, processFormulas } from "../../../utilities/rowProcessor"
import { db as dbCore } from "@budibase/backend-core" import { db as dbCore } from "@budibase/backend-core"
import sdk from "../../../sdk" import sdk from "../../../sdk"
@ -382,10 +383,17 @@ export class ExternalRequest {
} }
const display = linkedTable.primaryDisplay const display = linkedTable.primaryDisplay
for (let key of Object.keys(row[relationship.column])) { for (let key of Object.keys(row[relationship.column])) {
const related: Row = row[relationship.column][key] let relatedRow: Row = row[relationship.column][key]
// add this row as context for the relationship
for (let col of Object.values(linkedTable.schema)) {
if (col.type === FieldType.LINK && col.tableId === table._id) {
relatedRow[col.name] = [row]
}
}
relatedRow = processFormulas(linkedTable, relatedRow)
row[relationship.column][key] = { row[relationship.column][key] = {
primaryDisplay: display ? related[display] : undefined, primaryDisplay: display ? relatedRow[display] : undefined,
_id: related._id, _id: relatedRow._id,
} }
} }
} }