Browse Source

Merge pull request #7120 from nocodb/fix/7119-v2-links-api

fix: Extract row id value using title
pull/7121/head
Pranav C 1 year ago committed by GitHub
parent
commit
a5a982c6ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/nocodb/src/controllers/data-table.controller.ts
  2. 37
      packages/nocodb/src/db/BaseModelSqlv2.ts
  3. 8
      packages/nocodb/src/services/data-table.service.ts

8
packages/nocodb/src/controllers/data-table.controller.ts

@ -153,7 +153,13 @@ export class DataTableController {
@Param('columnId') columnId: string,
@Param('rowId') rowId: string,
@Body()
refRowIds: string | string[] | number | number[] | Record<string, any>,
refRowIds:
| string
| string[]
| number
| number[]
| Record<string, any>
| Record<string, any>[],
) {
return await this.dataTableService.nestedLink({
modelId,

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

@ -4869,7 +4869,9 @@ class BaseModelSqlv2 {
);
NcError.unprocessableEntity(
`Child record with id [${missingIds.join(', ')}] not found`,
`Child record with id [${extractIdsString(
missingIds,
)}] not found`,
);
}
@ -4878,8 +4880,11 @@ class BaseModelSqlv2 {
.filter((childRow) => !childRow[vChildCol.column_name])
// generate insert data for new links
.map((childRow) => ({
[vParentCol.column_name]: childRow[parentColumn.column_name],
[vChildCol.column_name]: row[childColumn.column_name],
[vParentCol.column_name]:
childRow[parentColumn.title] ??
childRow[parentColumn.column_name],
[vChildCol.column_name]:
row[childColumn.title] ?? row[childColumn.column_name],
}));
// if no new links, return true
@ -4930,7 +4935,9 @@ class BaseModelSqlv2 {
);
NcError.unprocessableEntity(
`Child record with id [${missingIds.join(', ')}] not found`,
`Child record with id [${extractIdsString(
missingIds,
)}] not found`,
);
}
}
@ -4980,7 +4987,9 @@ class BaseModelSqlv2 {
if (!childRow) {
NcError.unprocessableEntity(
`Child record with id [${childIds[0]}] not found`,
`Child record with id [${extractIdsString(
childIds,
)}] not found`,
);
}
}
@ -5106,7 +5115,9 @@ class BaseModelSqlv2 {
);
NcError.unprocessableEntity(
`Child record with id [${missingIds.join(', ')}] not found`,
`Child record with id [${extractIdsString(
missingIds,
)}] not found`,
);
}
}
@ -5154,7 +5165,9 @@ class BaseModelSqlv2 {
);
NcError.unprocessableEntity(
`Child record with id [${missingIds.join(', ')}] not found`,
`Child record with id [${extractIdsString(
missingIds,
)}] not found`,
);
}
}
@ -5208,7 +5221,9 @@ class BaseModelSqlv2 {
if (!childRow) {
NcError.unprocessableEntity(
`Child record with id [${childIds[0]}] not found`,
`Child record with id [${extractIdsString(
childIds,
)}] not found`,
);
}
}
@ -5674,4 +5689,10 @@ export function getListArgs(
return obj;
}
function extractIdsString(childIds: (string | number | Record<string, any>)[]) {
return childIds
.map((r) => (typeof r === 'object' ? JSON.stringify(r) : r))
.join(', ');
}
export { BaseModelSqlv2 };

8
packages/nocodb/src/services/data-table.service.ts

@ -371,7 +371,13 @@ export class DataTableService {
modelId: string;
columnId: string;
query: any;
refRowIds: string | string[] | number | number[] | Record<string, any>;
refRowIds:
| string
| string[]
| number
| number[]
| Record<string, any>
| Record<string, any>[];
rowId: string;
}) {
this.validateIds(param.refRowIds);

Loading…
Cancel
Save