From 0bb3de3d899bf3d289f6e862ea0dbbccdd317d62 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 6 Mar 2025 14:14:14 +0530 Subject: [PATCH 1/2] fix: logic for filter and message. --- .../collection-[collection]/document-[document]/delete.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte b/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte index eedf18f028..72cb3ae6e7 100644 --- a/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte +++ b/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte @@ -55,8 +55,8 @@ 'restrict' = 'Document can not be deleted' } - $: relAttributes = $attributes?.filter((attribute) => - isRelationship(attribute) + $: relAttributes = $attributes?.filter( + (attribute) => isRelationship(attribute) && attribute.side === 'parent' ) as Models.AttributeRelationship[]; From 080c5a6f3de9c893f111946311e1562ab1694ea4 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 20 Mar 2025 13:30:10 +0530 Subject: [PATCH 2/2] attempt: fix the content for relationship deletions. --- src/lib/components/trim.svelte | 3 ++- .../document-[document]/delete.svelte | 17 +++++++++++++---- .../collection-[collection]/table.svelte | 13 +++++++++++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/lib/components/trim.svelte b/src/lib/components/trim.svelte index 27da7d77f5..eb0bb99f92 100644 --- a/src/lib/components/trim.svelte +++ b/src/lib/components/trim.svelte @@ -3,8 +3,8 @@ import { throttle } from '$lib/helpers/functions'; import { onMount } from 'svelte'; - export let alternativeTrim = false; let showTooltip = false; + export let alternativeTrim = false; let container: HTMLSpanElement | null; onMount(onResize); @@ -21,6 +21,7 @@ bind:this={container} use:tooltip={{ disabled: !showTooltip, + appendTo: 'parent', content: container?.innerText ?? undefined, maxWidth: '30rem' }}> diff --git a/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte b/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte index 72cb3ae6e7..fa32d13ce6 100644 --- a/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte +++ b/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte @@ -2,9 +2,9 @@ import { goto } from '$app/navigation'; import { base } from '$app/paths'; import { page } from '$app/stores'; - import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; import { Alert, Modal, Trim } from '$lib/components'; import { Button, InputChoice } from '$lib/elements/forms'; + import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; import { TableBody, TableCell, @@ -17,7 +17,7 @@ import { addNotification } from '$lib/stores/notifications'; import { sdk } from '$lib/stores/sdk'; import { attributes, collection } from '../store'; - import { isRelationship } from './attributes/store'; + import { isRelationship, isRelationshipToMany } from './attributes/store'; import type { Models } from '@appwrite.io/console'; export let showDelete = false; @@ -52,11 +52,20 @@ enum Deletion { 'setNull' = 'Set document ID as NULL in all related documents', 'cascade' = 'All related documents will be deleted', - 'restrict' = 'Document can not be deleted' + 'restrict' = 'Document cannot be deleted' } $: relAttributes = $attributes?.filter( - (attribute) => isRelationship(attribute) && attribute.side === 'parent' + (attribute) => + isRelationship(attribute) && + // One-to-One are always included + (attribute.relationType === 'oneToOne' || + // One-to-Many: Only if parent is deleted + (attribute.relationType === 'oneToMany' && attribute.side === 'parent') || + // Many-to-One: Only include if child is deleted + (attribute.relationType === 'manyToOne' && attribute.side === 'child') || + // Many-to-Many: Only include if the parent is being deleted + (isRelationshipToMany(attribute) && attribute.side === 'parent')) ) as Models.AttributeRelationship[]; diff --git a/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/table.svelte b/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/table.svelte index fbfc7544e2..7eff77aff4 100644 --- a/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/table.svelte +++ b/src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/table.svelte @@ -152,8 +152,17 @@ 'restrict' = 'Document can not be deleted' } - $: relAttributes = $attributes?.filter((attribute) => - isRelationship(attribute) + $: relAttributes = $attributes?.filter( + (attribute) => + isRelationship(attribute) && + // One-to-One are always included + (attribute.relationType === 'oneToOne' || + // One-to-Many: Only if parent is deleted + (attribute.relationType === 'oneToMany' && attribute.side === 'parent') || + // Many-to-One: Only include if child is deleted + (attribute.relationType === 'manyToOne' && attribute.side === 'child') || + // Many-to-Many: Only include if the parent is being deleted + (isRelationshipToMany(attribute) && attribute.side === 'parent')) ) as Models.AttributeRelationship[]; let checked = false;