Merge pull request #13876 from Budibase/BUDI-7422/support-composite-keys
Fix key value updates in patch
This commit is contained in:
commit
905f32d084
|
@ -25,6 +25,7 @@ import {
|
|||
outputProcessing,
|
||||
} from "../../../utilities/rowProcessor"
|
||||
import { cloneDeep } from "lodash"
|
||||
import { generateIdForRow } from "./utils"
|
||||
|
||||
export async function handleRequest<T extends Operation>(
|
||||
operation: T,
|
||||
|
@ -55,11 +56,19 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
|||
throw { validation: validateResult.errors }
|
||||
}
|
||||
|
||||
const beforeRow = await sdk.rows.external.getRow(tableId, _id, {
|
||||
relationships: true,
|
||||
})
|
||||
|
||||
const response = await handleRequest(Operation.UPDATE, tableId, {
|
||||
id: breakRowIdField(_id),
|
||||
row: dataToUpdate,
|
||||
})
|
||||
const row = await sdk.rows.external.getRow(tableId, _id, {
|
||||
|
||||
// The id might have been changed, so the refetching would fail. Recalculating the id just in case
|
||||
const updatedId =
|
||||
generateIdForRow({ ...beforeRow, ...dataToUpdate }, table) || _id
|
||||
const row = await sdk.rows.external.getRow(tableId, updatedId, {
|
||||
relationships: true,
|
||||
})
|
||||
const enrichedRow = await outputProcessing(table, row, {
|
||||
|
|
|
@ -38,7 +38,7 @@ describe.each([
|
|||
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||
])("/rows (%s)", (__, dsProvider) => {
|
||||
])("/rows (%s)", (providerType, dsProvider) => {
|
||||
const isInternal = dsProvider === undefined
|
||||
const config = setup.getConfig()
|
||||
|
||||
|
@ -693,6 +693,49 @@ describe.each([
|
|||
})
|
||||
expect(resp.relationship.length).toBe(1)
|
||||
})
|
||||
|
||||
!isInternal &&
|
||||
// TODO: SQL is having issues creating composite keys
|
||||
providerType !== DatabaseName.SQL_SERVER &&
|
||||
it("should support updating fields that are part of a composite key", async () => {
|
||||
const tableRequest = saveTableRequest({
|
||||
primary: ["number", "string"],
|
||||
schema: {
|
||||
string: {
|
||||
type: FieldType.STRING,
|
||||
name: "string",
|
||||
},
|
||||
number: {
|
||||
type: FieldType.NUMBER,
|
||||
name: "number",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
delete tableRequest.schema.id
|
||||
|
||||
const table = await config.api.table.save(tableRequest)
|
||||
|
||||
const stringValue = generator.word()
|
||||
const naturalValue = generator.integer({ min: 0, max: 1000 })
|
||||
|
||||
const existing = await config.api.row.save(table._id!, {
|
||||
string: stringValue,
|
||||
number: naturalValue,
|
||||
})
|
||||
|
||||
expect(existing._id).toEqual(`%5B${naturalValue}%2C'${stringValue}'%5D`)
|
||||
|
||||
const row = await config.api.row.patch(table._id!, {
|
||||
_id: existing._id!,
|
||||
_rev: existing._rev!,
|
||||
tableId: table._id!,
|
||||
string: stringValue,
|
||||
number: 1500,
|
||||
})
|
||||
|
||||
expect(row._id).toEqual(`%5B${"1500"}%2C'${stringValue}'%5D`)
|
||||
})
|
||||
})
|
||||
|
||||
describe("destroy", () => {
|
||||
|
|
Loading…
Reference in New Issue