Merge pull request #14063 from Budibase/fix/switch-to-relationship-column
Updating filter fields to use relationship name rather than related table name
This commit is contained in:
commit
34e11d3b1f
|
@ -2,7 +2,6 @@ import { BannedSearchTypes } from "../constants"
|
||||||
|
|
||||||
export function getTableFields(tables, linkField) {
|
export function getTableFields(tables, linkField) {
|
||||||
const table = tables.find(table => table._id === linkField.tableId)
|
const table = tables.find(table => table._id === linkField.tableId)
|
||||||
// TODO: mdrury - add support for this with SQS at some point
|
|
||||||
if (!table || !table.sql) {
|
if (!table || !table.sql) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -11,7 +10,7 @@ export function getTableFields(tables, linkField) {
|
||||||
})
|
})
|
||||||
return linkFields.map(field => ({
|
return linkFields.map(field => ({
|
||||||
...field,
|
...field,
|
||||||
name: `${table.name}.${field.name}`,
|
name: `${linkField.name}.${field.name}`,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,20 +9,20 @@ import { db as dbCore, utils } from "@budibase/backend-core"
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import {
|
import {
|
||||||
AutoFieldSubType,
|
AutoFieldSubType,
|
||||||
|
BBReferenceFieldSubType,
|
||||||
Datasource,
|
Datasource,
|
||||||
EmptyFilterOption,
|
EmptyFilterOption,
|
||||||
BBReferenceFieldSubType,
|
|
||||||
FieldType,
|
FieldType,
|
||||||
|
RelationshipType,
|
||||||
|
Row,
|
||||||
RowSearchParams,
|
RowSearchParams,
|
||||||
SearchFilters,
|
SearchFilters,
|
||||||
|
SearchResponse,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
SortType,
|
SortType,
|
||||||
Table,
|
Table,
|
||||||
TableSchema,
|
TableSchema,
|
||||||
User,
|
User,
|
||||||
Row,
|
|
||||||
RelationshipType,
|
|
||||||
SearchResponse,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
|
@ -2084,6 +2084,28 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
isInternal &&
|
||||||
|
describe("no column error backwards compat", () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
table = await createTable({
|
||||||
|
name: {
|
||||||
|
name: "name",
|
||||||
|
type: FieldType.STRING,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("shouldn't error when column doesn't exist", async () => {
|
||||||
|
await expectSearch({
|
||||||
|
query: {
|
||||||
|
string: {
|
||||||
|
"1:something": "a",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).toMatch({ rows: [] })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// lucene can't count the total rows
|
// lucene can't count the total rows
|
||||||
!isLucene &&
|
!isLucene &&
|
||||||
describe("row counting", () => {
|
describe("row counting", () => {
|
||||||
|
|
|
@ -39,7 +39,10 @@ import {
|
||||||
import { dataFilters } from "@budibase/shared-core"
|
import { dataFilters } from "@budibase/shared-core"
|
||||||
|
|
||||||
const builder = new sql.Sql(SqlClient.SQL_LITE)
|
const builder = new sql.Sql(SqlClient.SQL_LITE)
|
||||||
const NO_SUCH_COLUMN_REGEX = new RegExp(`no such colum.+${USER_COLUMN_PREFIX}`)
|
const MISSING_COLUMN_REGEX = new RegExp(`no such column: .+`)
|
||||||
|
const USER_COLUMN_PREFIX_REGEX = new RegExp(
|
||||||
|
`no such column: .+${USER_COLUMN_PREFIX}`
|
||||||
|
)
|
||||||
|
|
||||||
function buildInternalFieldList(
|
function buildInternalFieldList(
|
||||||
table: Table,
|
table: Table,
|
||||||
|
@ -331,12 +334,16 @@ export async function search(
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const msg = typeof err === "string" ? err : err.message
|
const msg = typeof err === "string" ? err : err.message
|
||||||
const syncAndRepeat =
|
const syncAndRepeat =
|
||||||
(err.status === 400 && msg?.match(NO_SUCH_COLUMN_REGEX)) ||
|
(err.status === 400 && msg?.match(USER_COLUMN_PREFIX_REGEX)) ||
|
||||||
(err.status === 404 && msg?.includes(SQLITE_DESIGN_DOC_ID))
|
(err.status === 404 && msg?.includes(SQLITE_DESIGN_DOC_ID))
|
||||||
if (syncAndRepeat) {
|
if (syncAndRepeat) {
|
||||||
await sdk.tables.sqs.syncDefinition()
|
await sdk.tables.sqs.syncDefinition()
|
||||||
return search(options, table)
|
return search(options, table)
|
||||||
}
|
}
|
||||||
|
// previously the internal table didn't error when a column didn't exist in search
|
||||||
|
if (err.status === 400 && msg?.match(MISSING_COLUMN_REGEX)) {
|
||||||
|
return { rows: [] }
|
||||||
|
}
|
||||||
throw new Error(`Unable to search by SQL - ${msg}`, { cause: err })
|
throw new Error(`Unable to search by SQL - ${msg}`, { cause: err })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue