First PR comments.

This commit is contained in:
mike12345567 2024-06-24 12:43:26 +01:00
parent 05ea231d20
commit 965725d022
3 changed files with 24 additions and 26 deletions

View File

@ -176,24 +176,13 @@ export class ExternalRequest<T extends Operation> {
const relationshipColumns = sdk.rows.filters.getRelationshipColumns(table)
filters = sdk.rows.filters.updateFilterKeys(
filters,
relationshipColumns
.map(({ name, definition }) => {
relationshipColumns.map(({ name, definition }) => {
const { tableName } = breakExternalTableId(definition.tableId)
return {
original: name,
updated: tableName!,
}
})
// don't update table names - include this for context incase a column would be replaced
.concat(
tables.map(table => {
const tableName = table.originalName || table.name
return {
original: tableName,
updated: tableName,
}
})
)
)
const primary = table.primary
// if passed in array need to copy for shifting etc

View File

@ -1954,6 +1954,7 @@ describe.each([
!isLucene &&
// It also can't work for in-memory searching because the related table name
// isn't available.
!isInMemory &&
describe("relations", () => {
let productCategoryTable: Table, productCatRows: Row[]

View File

@ -4,16 +4,24 @@ import {
SearchFilters,
Table,
} from "@budibase/types"
import { isPlainObject } from "lodash"
export function getRelationshipColumns(table: Table): {
name: string
definition: RelationshipFieldMetadata
}[] {
return Object.entries(table.schema)
.filter(entry => entry[1].type === FieldType.LINK)
.map(entry => ({
// performing this with a for loop rather than an array filter improves
// type guarding, as no casts are required
const linkEntries: [string, RelationshipFieldMetadata][] = []
for (let entry of Object.entries(table.schema)) {
if (entry[1].type === FieldType.LINK) {
const linkColumn: RelationshipFieldMetadata = entry[1]
linkEntries.push([entry[0], linkColumn])
}
}
return linkEntries.map(entry => ({
name: entry[0],
definition: entry[1] as RelationshipFieldMetadata,
definition: entry[1],
}))
}
@ -21,7 +29,7 @@ export function getTableIDList(
tables: Table[]
): { name: string; id: string }[] {
return tables
.filter(table => table.originalName)
.filter(table => table.originalName && table._id)
.map(table => ({ id: table._id!, name: table.originalName! }))
}
@ -32,7 +40,7 @@ export function updateFilterKeys(
const makeFilterKeyRegex = (str: string) =>
new RegExp(`^${str}\\.|:${str}\\.`)
for (let filter of Object.values(filters)) {
if (typeof filter !== "object") {
if (!isPlainObject(filter)) {
continue
}
for (let [key, keyFilter] of Object.entries(filter)) {