From 8bc51f2282296c42d89957fa2f010fc4a0daaa89 Mon Sep 17 00:00:00 2001 From: Jamieson Baker Date: Thu, 6 May 2021 20:53:21 +1000 Subject: [PATCH] feat: add schema support for orphanedRowAction Adds support for setting the action for orphaned relation rows when using separate entity definitions Fixes #7417 --- src/entity-schema/EntitySchemaRelationOptions.ts | 4 ++++ src/entity-schema/EntitySchemaTransformer.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/entity-schema/EntitySchemaRelationOptions.ts b/src/entity-schema/EntitySchemaRelationOptions.ts index 0502fc67e6..f5969eb4dd 100644 --- a/src/entity-schema/EntitySchemaRelationOptions.ts +++ b/src/entity-schema/EntitySchemaRelationOptions.ts @@ -98,4 +98,8 @@ export interface EntitySchemaRelationOptions { */ deferrable?: DeferrableType; + /** + * When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted. + */ + orphanedRowAction?: "nullify" | "delete"; } diff --git a/src/entity-schema/EntitySchemaTransformer.ts b/src/entity-schema/EntitySchemaTransformer.ts index e53eb2c981..ecff559828 100644 --- a/src/entity-schema/EntitySchemaTransformer.ts +++ b/src/entity-schema/EntitySchemaTransformer.ts @@ -136,7 +136,8 @@ export class EntitySchemaTransformer { onUpdate: relationSchema.onUpdate, deferrable: relationSchema.deferrable, primary: relationSchema.primary, - persistence: relationSchema.persistence + persistence: relationSchema.persistence, + orphanedRowAction: relationSchema.orphanedRowAction } };