Aller au contenu principal

Entity Inheritance Hierarchy

Understanding the base class hierarchy for all database entities.

Inheritance Tree

BaseEntity

The root class for all entities:

export abstract class BaseEntity {
@PrimaryGeneratedColumn("uuid")
id: string;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;

@Column({ nullable: true })
isActive?: boolean;

@Column({ nullable: true })
isArchived?: boolean;

@DeleteDateColumn()
deletedAt?: Date;

@Column({ nullable: true })
archivedAt?: Date;
}

TenantBaseEntity

Adds tenant scoping:

export abstract class TenantBaseEntity extends BaseEntity {
@Column({ nullable: true })
tenantId: string;

@ManyToOne(() => Tenant)
tenant?: Tenant;
}

Usage: Entities scoped to a tenant but not organization-specific (e.g., Role, User settings).

TenantOrganizationBaseEntity

Adds organization scoping:

export abstract class TenantOrganizationBaseEntity extends TenantBaseEntity {
@Column({ nullable: true })
organizationId: string;

@ManyToOne(() => Organization)
organization?: Organization;
}

Usage: Most business entities (Task, Employee, Invoice, etc.).

TranslationBase

For multi-language content:

export abstract class TranslationBase extends BaseEntity {
@Column()
languageCode: string;
}

Usage: ProductTranslation, ProductCategoryTranslation, etc.

Which Base Class to Use

ScenarioBase Class
System-level entityBaseEntity
Tenant-scopedTenantBaseEntity
Organization-scoped (most)TenantOrganizationBaseEntity
Translatable contentTranslationBase