π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix: update column title handling for relation types and add versioning for LinkToAnotherRecord
Pranav C560518eebbff
diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.tsindex f4593b793a..6e96fd8dea 100644--- a/packages/nocodb/src/services/columns.service.ts+++ b/packages/nocodb/src/services/columns.service.ts@@ -5080,10 +5080,20 @@ export class ColumnsService implements IColumnsService {.type as RelationTypes,);+ const relationType = (param.column as Pick<LinkToAnotherColumnReqType, 'type'>).type as RelationTypes;++ // Use singular for ONE_TO_ONE and MANY_TO_ONE, plural for others+ const defaultTitle = [+ RelationTypes.ONE_TO_ONE,+ RelationTypes.MANY_TO_ONE,+ ].includes(relationType)+ ? singularize(refTable.title)+ : pluralize(refTable.title);+savedColumn = await Column.insert(context, {title: getUniqueColumnAliasName(await table.getColumns(context),- param.column.title ?? pluralize(refTable.title),+ param.column.title ?? defaultTitle,),uidt: isLinks ? UITypes.Links : UITypes.LinkToAnotherRecord,@@ -5114,6 +5124,14 @@ export class ColumnsService implements IColumnsService {...crossBaseLinkProps,});+ // Use singular for ONE_TO_ONE and MANY_TO_ONE, plural for others+ const reverseDefaultTitle = [+ RelationTypes.ONE_TO_ONE,+ RelationTypes.MANY_TO_ONE,+ ].includes(revType)+ ? singularize(table.title)+ : pluralize(table.title);+const parentRelCol = await Column.insert(refContext, {title: getUniqueColumnAliasName([@@ -5121,7 +5139,7 @@ export class ColumnsService implements IColumnsService {// if self ref include saved column...(table.id === refTable.id ? [savedColumn] : []),],- pluralize(table.title),+ reverseDefaultTitle,),uidt: isLinks ? UITypes.Links : UITypes.LinkToAnotherRecord,type: revType,diff --git a/packages/nocodb/tests/unit/factory/column.ts b/packages/nocodb/tests/unit/factory/column.tsindex 28c2153d4f..22fb524035 100644--- a/packages/nocodb/tests/unit/factory/column.ts+++ b/packages/nocodb/tests/unit/factory/column.ts@@ -12,6 +12,7 @@ import type {View,} from '../../../src/models';import type init from '../init';+import { verify } from 'crypto';type Context = Awaited<ReturnType<typeof init>>;@@ -922,6 +923,11 @@ const createColumn = async (.set('xc-auth', context.token).send({...columnAttr,+ ...(columnAttr.uidt === UITypes.LinkToAnotherRecord+ ? {+ version: 1,+ }+ : {}),});if (response.status >= 400 && option?.throwError) {if (option?.responseAsError) {@@ -956,6 +962,11 @@ const createColumn2 = async ({.set('xc-auth', context.token).send({...columnAttr,+ ...(columnAttr.uidt === UITypes.LinkToAnotherRecord+ ? {+ version: 1,+ }+ : {}),});if (response.status >= 400 && option?.throwError) {throw response.error;