Browse Source

fix: link audit - handle if relation is between non-pk columns

pull/8367/head
Pranav C 4 months ago
parent
commit
68b21e190b
  1. 27
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 19
      packages/nocodb/tests/unit/rest/tests/column.test.ts

27
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -5722,8 +5722,13 @@ class BaseModelSqlv2 {
{
const linkedHmRowObj = await this.execAndParse(
this.dbDriver(childTn)
.select(childTable.primaryKeys.map((pk) => pk.column_name))
.select(`${childTable.table_name}.${childColumn.column_name}`)
.select(
...new Set(
[childColumn, ...childTable.primaryKeys].map(
(col) => `${childTable.table_name}.${col.column_name}`,
),
),
)
.where(_wherePk(childTable.primaryKeys, childId)),
null,
{ raw: true, first: true },
@ -5835,8 +5840,13 @@ class BaseModelSqlv2 {
} else {
const linkedHmRowObj = await this.execAndParse(
this.dbDriver(childTn)
.select(childTable.primaryKeys.map((pk) => pk.column_name))
.select(childColumn.column_name)
.select(
...new Set(
[childColumn, ...childTable.primaryKeys].map(
(col) => col.column_name,
),
),
)
.where(_wherePk(childTable.primaryKeys, rowId)),
null,
{ raw: true, first: true },
@ -5915,8 +5925,13 @@ class BaseModelSqlv2 {
// 1. check current row is linked with another child
linkedCurrentOoRowObj = await this.execAndParse(
this.dbDriver(childTn)
.select(childTable.primaryKeys.map((pk) => pk.column_name))
.select(childColumn.column_name)
.select(
...new Set(
[childColumn, ...childTable.primaryKeys].map(
(col) => col.column_name,
),
),
)
.where(_wherePk(childTable.primaryKeys, rowId)),
null,
{ raw: true, first: true },

19
packages/nocodb/tests/unit/rest/tests/column.test.ts

@ -6,12 +6,14 @@ import init from '../../init';
import { createProject } from '../../factory/base';
import { createTable } from '../../factory/table';
import { createBulkRows, createChildRow, listRow } from '../../factory/row';
import type { NcContext } from '../../../../src/interface/config';
import type Base from '~/models/Base';
// Test case list
// 1. Advanced link creation
function columnTests() {
let context;
let ctx: NcContext;
let base: Base;
const defaultTableColumns = [
@ -30,6 +32,11 @@ function columnTests() {
base = await createProject(context);
ctx = {
workspace_id: base.fk_workspace_id,
base_id: base.id,
};
console.timeEnd('#### columnTypeSpecificTests');
});
@ -52,10 +59,10 @@ function columnTests() {
],
});
const pkColumn = (await country.getColumns(context)).find(
const pkColumn = (await country.getColumns(ctx)).find(
(column) => column.pk,
);
const fkColumn = (await city.getColumns(context)).find(
const fkColumn = (await city.getColumns(ctx)).find(
(column) => column.title === 'CountryId',
);
@ -177,16 +184,16 @@ function columnTests() {
],
});
const pkColumn = (await actor.getColumns(context)).find(
const pkColumn = (await actor.getColumns(ctx)).find(
(column) => column.pk,
);
const refPkColumn = (await film.getColumns(context)).find(
const refPkColumn = (await film.getColumns(ctx)).find(
(column) => column.pk,
);
const junColId = (await filmActor.getColumns(context)).find(
const junColId = (await filmActor.getColumns(ctx)).find(
(column) => column.title === 'ActorId',
);
const juRefColId = (await filmActor.getColumns(context)).find(
const juRefColId = (await filmActor.getColumns(ctx)).find(
(column) => column.title === 'FilmId',
);

Loading…
Cancel
Save