First PR comments.
This commit is contained in:
parent
05ea231d20
commit
965725d022
|
@ -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 }) => {
|
||||
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,
|
||||
}
|
||||
})
|
||||
)
|
||||
relationshipColumns.map(({ name, definition }) => {
|
||||
const { tableName } = breakExternalTableId(definition.tableId)
|
||||
return {
|
||||
original: name,
|
||||
updated: tableName!,
|
||||
}
|
||||
})
|
||||
)
|
||||
const primary = table.primary
|
||||
// if passed in array need to copy for shifting etc
|
||||
|
|
|
@ -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[]
|
||||
|
||||
|
|
|
@ -4,24 +4,32 @@ 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 => ({
|
||||
name: entry[0],
|
||||
definition: entry[1] as RelationshipFieldMetadata,
|
||||
}))
|
||||
// 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],
|
||||
}))
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
|
Loading…
Reference in New Issue