Skip to content

Commit beef847

Browse files
authored
Merge pull request #2350 from teableio/fix/autonumber-meta-fallback
fix: handle autonumber fallback for non-generated columns T1474
2 parents 66ae6e9 + e62fcb4 commit beef847

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

apps/nestjs-backend/src/features/record/computed/services/computed-dependency-collector.service.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
IConditionalRollupFieldOptions,
1111
IConditionalLookupOptions,
1212
ILookupLinkOptionsVo,
13+
AutoNumberFieldCore,
1314
FieldCore,
1415
TableDomain,
1516
} from '@teable/core';
@@ -1436,6 +1437,17 @@ export class ComputedDependencyCollectorService {
14361437
return rows.map((row) => row.id).filter(Boolean);
14371438
}
14381439

1440+
private getAutoNumberFieldIds(table: TableDomain, excludeFieldIds?: string[]): string[] {
1441+
const excluded = new Set(excludeFieldIds ?? []);
1442+
return table.fieldList
1443+
.filter(
1444+
(field): field is AutoNumberFieldCore =>
1445+
field.type === FieldType.AutoNumber && !excluded.has(field.id)
1446+
)
1447+
.filter((field) => !field.getIsPersistedAsGeneratedColumn?.())
1448+
.map((field) => field.id);
1449+
}
1450+
14391451
private addContextFreeFormulasToImpact(
14401452
impact: IComputedImpactByTable,
14411453
tableId: string,
@@ -1587,6 +1599,8 @@ export class ComputedDependencyCollectorService {
15871599
excludeFieldIds
15881600
);
15891601
this.addContextFreeFormulasToImpact(impact, tableId, contextFreeFormulaIds);
1602+
const autoNumberFieldIds = this.getAutoNumberFieldIds(entryDomain, excludeFieldIds);
1603+
this.addContextFreeFormulasToImpact(impact, tableId, autoNumberFieldIds);
15901604

15911605
if (!Object.keys(impact).length) {
15921606
return { impact: {}, tableDomains: new Map(seedTableDomains) };

apps/nestjs-backend/src/features/record/computed/services/record-computed-update.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class RecordComputedUpdateService {
5757
// Skip formula persisted as generated columns
5858
return match(f)
5959
.when(isFormulaField, (f) => !f.getIsPersistedAsGeneratedColumn())
60-
.with({ type: FieldType.AutoNumber }, () => false)
60+
.with({ type: FieldType.AutoNumber }, (f) => !f.getIsPersistedAsGeneratedColumn())
6161
.with({ type: FieldType.CreatedTime }, () => isLookupStyle)
6262
.with({ type: FieldType.LastModifiedTime }, () => isLookupStyle)
6363
.with({ type: FieldType.CreatedBy }, (f) => isLookupStyle || !isPersistedGenerated(f))

apps/nestjs-backend/src/features/record/query-builder/field-select-visitor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { DbFieldType, FieldType, isLinkLookupOptions, DriverClient } from '@teab
2828
// no driver-specific logic here; use dialect for differences
2929
import type { Knex } from 'knex';
3030
import type { IDbProvider } from '../../../db-provider/db.provider.interface';
31+
import { AUTO_NUMBER_FIELD_NAME } from '../../field/constant';
3132
import { isSystemUserField } from '../../field/fields-utils';
3233
import type { IFieldSelectName } from './field-select.type';
3334
import type {
@@ -390,6 +391,14 @@ export class FieldSelectVisitor implements IFieldVisitor<IFieldSelectName> {
390391
}
391392

392393
visitAutoNumberField(field: AutoNumberFieldCore): IFieldSelectName {
394+
if (field.isLookup) {
395+
return this.checkAndSelectLookupField(field);
396+
}
397+
if (this.rawProjection) {
398+
const selector = this.generateColumnSelect(AUTO_NUMBER_FIELD_NAME);
399+
this.state.setSelection(field.id, selector);
400+
return selector;
401+
}
393402
return this.checkAndSelectLookupField(field);
394403
}
395404

packages/core/src/models/field/derivate/auto-number.field.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export class AutoNumberFieldCore extends FormulaAbstractCore {
5555
return autoNumberCellValueSchema.nullable().safeParse(value);
5656
}
5757

58+
getIsPersistedAsGeneratedColumn() {
59+
return this.meta?.persistedAsGeneratedColumn || false;
60+
}
5861
getExpression() {
5962
return this.options.expression;
6063
}

0 commit comments

Comments
 (0)