From c783a462434691cad8bdd52ba8a57f53ad47c30a Mon Sep 17 00:00:00 2001 From: Alexander Sandor <137198655+SandPod@users.noreply.github.com> Date: Tue, 10 Dec 2024 08:50:32 +0100 Subject: [PATCH] fix: Update default refential action values. (#221) * fix: Document all default referential values. * fix: Apply same fix to versioned documentation. --- .../03-relations/05-referential-actions.md | 15 +++++++++++++-- .../03-relations/05-referential-actions.md | 17 ++++++++++++++--- .../03-relations/05-referential-actions.md | 15 +++++++++++++-- .../03-relations/05-referential-actions.md | 15 +++++++++++++-- 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/docs/06-concepts/06-database/03-relations/05-referential-actions.md b/docs/06-concepts/06-database/03-relations/05-referential-actions.md index e6822ea6..a5c58de4 100644 --- a/docs/06-concepts/06-database/03-relations/05-referential-actions.md +++ b/docs/06-concepts/06-database/03-relations/05-referential-actions.md @@ -20,10 +20,21 @@ Use the following syntax to apply referential actions relation(onUpdate=, onDelete=) ``` -For instance, the default behavior in Serverpod can be expressed as. +## Default values +If no referential actions are specified, the default behavior will be applied. + +If the relation is defined as an [object relation](one-to-one#with-an-object), the default behavior is `NoAction` for both onUpdate and onDelete. + +```yaml +parent: Model?, relation(onUpdate=NoAction, onDelete=NoAction) +``` + + +If the relation is defined as an [id relation](one-to-one#with-an-id-field), the default behavior is `NoAction` for onUpdate and `Cascade` for onDelete. + ```yaml -relation(onUpdate=NoAction, onDelete=Cascade) +parentId: int?, relation(parent=model_table, onUpdate=NoAction, onDelete=Cascade) ``` :::info diff --git a/versioned_docs/version-1.2.0/05-concepts/06-database/03-relations/05-referential-actions.md b/versioned_docs/version-1.2.0/05-concepts/06-database/03-relations/05-referential-actions.md index 9f885ae9..6c1a5eb6 100644 --- a/versioned_docs/version-1.2.0/05-concepts/06-database/03-relations/05-referential-actions.md +++ b/versioned_docs/version-1.2.0/05-concepts/06-database/03-relations/05-referential-actions.md @@ -20,11 +20,23 @@ Use the following syntax to apply referential actions relation(onUpdate=, onDelete=) ``` -For instance, the default behavior in Serverpod can be expressed as. +## Default values +If no referential actions are specified, the default behavior will be applied. + +If the relation is defined as an [object relation](one-to-one#with-an-object), the default behavior is `NoAction` for both onUpdate and onDelete. ```yaml -relation(onUpdate=NoAction, onDelete=Cascade) +parent: Model?, relation(onUpdate=NoAction, onDelete=NoAction) ``` + + +If the relation is defined as an [id relation](one-to-one#with-an-id-field), the default behavior is `NoAction` for onUpdate and `Cascade` for onDelete. + + +```yaml +parentId: int?, relation(parent=model_table, onUpdate=NoAction, onDelete=Cascade) +``` + :::info The sequence of onUpdate and onDelete is interchangeable. @@ -41,4 +53,3 @@ fields: ``` In the given example, if the `example` parent is updated, the `parentId` will be set to null. If the parent is deleted, no action will be taken for parentId. - diff --git a/versioned_docs/version-2.0.0/05-concepts/06-database/03-relations/05-referential-actions.md b/versioned_docs/version-2.0.0/05-concepts/06-database/03-relations/05-referential-actions.md index ea663135..6c1a5eb6 100644 --- a/versioned_docs/version-2.0.0/05-concepts/06-database/03-relations/05-referential-actions.md +++ b/versioned_docs/version-2.0.0/05-concepts/06-database/03-relations/05-referential-actions.md @@ -20,10 +20,21 @@ Use the following syntax to apply referential actions relation(onUpdate=, onDelete=) ``` -For instance, the default behavior in Serverpod can be expressed as. +## Default values +If no referential actions are specified, the default behavior will be applied. + +If the relation is defined as an [object relation](one-to-one#with-an-object), the default behavior is `NoAction` for both onUpdate and onDelete. + +```yaml +parent: Model?, relation(onUpdate=NoAction, onDelete=NoAction) +``` + + +If the relation is defined as an [id relation](one-to-one#with-an-id-field), the default behavior is `NoAction` for onUpdate and `Cascade` for onDelete. + ```yaml -relation(onUpdate=NoAction, onDelete=Cascade) +parentId: int?, relation(parent=model_table, onUpdate=NoAction, onDelete=Cascade) ``` :::info diff --git a/versioned_docs/version-2.1.0/06-concepts/06-database/03-relations/05-referential-actions.md b/versioned_docs/version-2.1.0/06-concepts/06-database/03-relations/05-referential-actions.md index e6822ea6..a5c58de4 100644 --- a/versioned_docs/version-2.1.0/06-concepts/06-database/03-relations/05-referential-actions.md +++ b/versioned_docs/version-2.1.0/06-concepts/06-database/03-relations/05-referential-actions.md @@ -20,10 +20,21 @@ Use the following syntax to apply referential actions relation(onUpdate=, onDelete=) ``` -For instance, the default behavior in Serverpod can be expressed as. +## Default values +If no referential actions are specified, the default behavior will be applied. + +If the relation is defined as an [object relation](one-to-one#with-an-object), the default behavior is `NoAction` for both onUpdate and onDelete. + +```yaml +parent: Model?, relation(onUpdate=NoAction, onDelete=NoAction) +``` + + +If the relation is defined as an [id relation](one-to-one#with-an-id-field), the default behavior is `NoAction` for onUpdate and `Cascade` for onDelete. + ```yaml -relation(onUpdate=NoAction, onDelete=Cascade) +parentId: int?, relation(parent=model_table, onUpdate=NoAction, onDelete=Cascade) ``` :::info