diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 743cce410b..04e77fbe62 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -136,16 +136,15 @@ export async function importToRows( // We use a reference to table here and update it after input processing, // so that we can auto increment auto IDs in imported data properly - const processed = await inputProcessing(userId, table, row, { + row = await inputProcessing(userId, table, row, { noAutoRelationships: true, }) - row = processed // However here we must reference the original table, as we want to mutate // the real schema of the table passed in, not the clone used for // incrementing auto IDs for (const [fieldName, schema] of Object.entries(originalTable.schema)) { - if (schema.type === FieldType.LINK) { + if (schema.type === FieldType.LINK && data.find(row => row[fieldName])) { throw new HTTPError( `Can't bulk import relationship fields for internal databases, found value in field "${fieldName}"`, 400 diff --git a/packages/server/src/api/routes/tests/application.spec.ts b/packages/server/src/api/routes/tests/application.spec.ts index 729f899379..6d85cdbda9 100644 --- a/packages/server/src/api/routes/tests/application.spec.ts +++ b/packages/server/src/api/routes/tests/application.spec.ts @@ -1,3 +1,5 @@ +import { DEFAULT_TABLES } from "../../../db/defaultData/datasource_bb_default" + jest.mock("../../../utilities/redis", () => ({ init: jest.fn(), getLocksById: () => { @@ -447,4 +449,18 @@ describe("/applications", () => { expect(devLogs.data.length).toBe(0) }) }) + + describe("POST /api/applications/:appId/sample", () => { + it("should be able to add sample data", async () => { + await config.api.application.addSampleData(config.getAppId()) + for (let table of DEFAULT_TABLES) { + const res = await config.api.row.search( + table._id!, + { query: {} }, + { status: 200 } + ) + expect(res.rows.length).not.toEqual(0) + } + }) + }) })