Skip to content

Commit 080c5a6

Browse files
committed
attempt: fix the content for relationship deletions.
1 parent 0bb3de3 commit 080c5a6

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/lib/components/trim.svelte

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import { throttle } from '$lib/helpers/functions';
44
import { onMount } from 'svelte';
55
6-
export let alternativeTrim = false;
76
let showTooltip = false;
7+
export let alternativeTrim = false;
88
let container: HTMLSpanElement | null;
99
1010
onMount(onResize);
@@ -21,6 +21,7 @@
2121
bind:this={container}
2222
use:tooltip={{
2323
disabled: !showTooltip,
24+
appendTo: 'parent',
2425
content: container?.innerText ?? undefined,
2526
maxWidth: '30rem'
2627
}}>

src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/delete.svelte

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import { goto } from '$app/navigation';
33
import { base } from '$app/paths';
44
import { page } from '$app/stores';
5-
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
65
import { Alert, Modal, Trim } from '$lib/components';
76
import { Button, InputChoice } from '$lib/elements/forms';
7+
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
88
import {
99
TableBody,
1010
TableCell,
@@ -17,7 +17,7 @@
1717
import { addNotification } from '$lib/stores/notifications';
1818
import { sdk } from '$lib/stores/sdk';
1919
import { attributes, collection } from '../store';
20-
import { isRelationship } from './attributes/store';
20+
import { isRelationship, isRelationshipToMany } from './attributes/store';
2121
import type { Models } from '@appwrite.io/console';
2222
2323
export let showDelete = false;
@@ -52,11 +52,20 @@
5252
enum Deletion {
5353
'setNull' = 'Set document ID as NULL in all related documents',
5454
'cascade' = 'All related documents will be deleted',
55-
'restrict' = 'Document can not be deleted'
55+
'restrict' = 'Document cannot be deleted'
5656
}
5757
5858
$: relAttributes = $attributes?.filter(
59-
(attribute) => isRelationship(attribute) && attribute.side === 'parent'
59+
(attribute) =>
60+
isRelationship(attribute) &&
61+
// One-to-One are always included
62+
(attribute.relationType === 'oneToOne' ||
63+
// One-to-Many: Only if parent is deleted
64+
(attribute.relationType === 'oneToMany' && attribute.side === 'parent') ||
65+
// Many-to-One: Only include if child is deleted
66+
(attribute.relationType === 'manyToOne' && attribute.side === 'child') ||
67+
// Many-to-Many: Only include if the parent is being deleted
68+
(isRelationshipToMany(attribute) && attribute.side === 'parent'))
6069
) as Models.AttributeRelationship[];
6170
</script>
6271

src/routes/(console)/project-[project]/databases/database-[database]/collection-[collection]/table.svelte

+11-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,17 @@
152152
'restrict' = 'Document can not be deleted'
153153
}
154154
155-
$: relAttributes = $attributes?.filter((attribute) =>
156-
isRelationship(attribute)
155+
$: relAttributes = $attributes?.filter(
156+
(attribute) =>
157+
isRelationship(attribute) &&
158+
// One-to-One are always included
159+
(attribute.relationType === 'oneToOne' ||
160+
// One-to-Many: Only if parent is deleted
161+
(attribute.relationType === 'oneToMany' && attribute.side === 'parent') ||
162+
// Many-to-One: Only include if child is deleted
163+
(attribute.relationType === 'manyToOne' && attribute.side === 'child') ||
164+
// Many-to-Many: Only include if the parent is being deleted
165+
(isRelationshipToMany(attribute) && attribute.side === 'parent'))
157166
) as Models.AttributeRelationship[];
158167
159168
let checked = false;

0 commit comments

Comments
 (0)