Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

feat: links as ltar

DarkPhoenix2704346413de2fdc
diff --git a/packages/nocodb/src/constants/index.ts b/packages/nocodb/src/constants/index.ts
index ac78ab9bbc..f933722561 100644
--- a/packages/nocodb/src/constants/index.ts
+++ b/packages/nocodb/src/constants/index.ts
@@ -23,6 +23,7 @@ export const NC_EMAIL_ASSETS_BASE_URL = 'https://cdn.nocodb.com/emails/v2';
export const NC_RECURSIVE_MAX_DEPTH = 7;
export const QUERY_STRING_FIELD_ID_ON_RESULT = 'fieldIdOnResult';
+export const QUERY_STRING_LINKS_AS_LTAR = 'linksAsLtar';
export const S3_PATCH_KEYS = [
'uploads',
diff --git a/packages/nocodb/src/schema/swagger-v3.json b/packages/nocodb/src/schema/swagger-v3.json
index 1324bc5e7e..39b8d11a5b 100644
--- a/packages/nocodb/src/schema/swagger-v3.json
+++ b/packages/nocodb/src/schema/swagger-v3.json
@@ -3877,6 +3877,15 @@
"in": "query",
"description": "***View Identifier***. Allows you to fetch records that are currently visible within a specific view. API retrieves records in the order they are displayed if the SORT option is enabled within that view.\n\nAdditionally, if you specify a `sort` query parameter, it will take precedence over any sorting configuration defined in the view. If you specify a `where` query parameter, it will be applied over the filtering configuration defined in the view. \n\nBy default, all fields, including those that are disabled within the view, are included in the response. To explicitly specify which fields to include or exclude, you can use the `fields` query parameter to customize the output according to your requirements."
},
+ {
+ "schema": {
+ "type": "string",
+ "enum": ["true"]
+ },
+ "name": "linksAsLtar",
+ "in": "query",
+ "description": "When set to `true`, Links fields will return full linked record data (id and display value) instead of just a count. This makes Links fields behave like LinkToAnotherRecord (LTAR) fields in the response."
+ },
{
"required": true,
"$ref": "#/components/parameters/xc-token"
@@ -4285,6 +4294,15 @@
"name": "fields",
"description": "Allows you to specify the fields that you wish to include from the linked records in your API response. By default, only Primary Key and associated display value field is included.\n\nExample: `fields=[\"field1\",\"field2\"]` or `fields=field1,field2` will include only 'field1' and 'field2' in the API response."
},
+ {
+ "schema": {
+ "type": "string",
+ "enum": ["true"]
+ },
+ "name": "linksAsLtar",
+ "in": "query",
+ "description": "When set to `true`, Links fields will return full linked record data (id and display value) instead of just a count. This makes Links fields behave like LinkToAnotherRecord (LTAR) fields in the response."
+ },
{
"required": true,
"$ref": "#/components/parameters/xc-token"
diff --git a/packages/nocodb/src/services/v3/data-v3.service.ts b/packages/nocodb/src/services/v3/data-v3.service.ts
index 1ad0d420e7..4284f947b3 100644
--- a/packages/nocodb/src/services/v3/data-v3.service.ts
+++ b/packages/nocodb/src/services/v3/data-v3.service.ts
@@ -30,6 +30,7 @@ import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import {
MAX_NESTING_DEPTH,
QUERY_STRING_FIELD_ID_ON_RESULT,
+ QUERY_STRING_LINKS_AS_LTAR,
V3_DATA_PAYLOAD_LIMIT,
} from '~/constants';
import { processConcurrently, reuseOrSave } from '~/utils';
@@ -129,6 +130,7 @@ export class DataV3Service {
skipSubstitutingColumnIds?: boolean;
reuse?: ReusableParams;
depth?: number;
+ linksAsLtar?: boolean;
}): Promise<DataRecord> {
const {
context,
@@ -141,6 +143,7 @@ export class DataV3Service {
skipSubstitutingColumnIds,
reuse = {},
depth = 0,
+ linksAsLtar = false,
} = param;
const getPrimaryKey = (column: Column) => {
@@ -188,7 +191,10 @@ export class DataV3Service {
// Handle LTAR fields if columns are provided
if (columns) {
const column = columns.find((col) => col.title === key);
- if (column?.uidt === UITypes.LinkToAnotherRecord) {
+ if (
+ column?.uidt === UITypes.LinkToAnotherRecord ||
+ (column?.uidt === UITypes.Links && linksAsLtar)
+ ) {
if (Array.isArray(value)) {
// Check depth limit to prevent unbounded recursion
if (depth >= MAX_NESTING_DEPTH) {
@@ -302,6 +308,7 @@ export class DataV3Service {
skipSubstitutingColumnIds?: boolean;
reuse?: ReusableParams;
depth?: number;
+ linksAsLtar?: boolean;
}): Promise<DataRecord[]> {
const { records } = param;
@@ -444,6 +451,8 @@ export class DataV3Service {
queryParams: param.query,
});
+ const linksAsLtar = param.query[QUERY_STRING_LINKS_AS_LTAR] === 'true';
+
// Transform records with LTAR handling
const transformedRecords = await this.transformRecordsToV3Format({
context: context,
@@ -457,6 +466,7 @@ export class DataV3Service {
param.query[QUERY_STRING_FIELD_ID_ON_RESULT] === 'true',
reuse: {}, // Create reuse cache for this data list operation
depth: 0, // Start at depth 0 for main records
+ linksAsLtar,
});
if (!pagination) {