|
2 | 2 | import { goto } from '$app/navigation';
|
3 | 3 | import { base } from '$app/paths';
|
4 | 4 | import { page } from '$app/stores';
|
5 |
| - import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; |
6 | 5 | import { Alert, Modal, Trim } from '$lib/components';
|
7 | 6 | import { Button, InputChoice } from '$lib/elements/forms';
|
| 7 | + import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; |
8 | 8 | import {
|
9 | 9 | TableBody,
|
10 | 10 | TableCell,
|
|
17 | 17 | import { addNotification } from '$lib/stores/notifications';
|
18 | 18 | import { sdk } from '$lib/stores/sdk';
|
19 | 19 | import { attributes, collection } from '../store';
|
20 |
| - import { isRelationship } from './attributes/store'; |
| 20 | + import { isRelationship, isRelationshipToMany } from './attributes/store'; |
21 | 21 | import type { Models } from '@appwrite.io/console';
|
22 | 22 |
|
23 | 23 | export let showDelete = false;
|
|
52 | 52 | enum Deletion {
|
53 | 53 | 'setNull' = 'Set document ID as NULL in all related documents',
|
54 | 54 | 'cascade' = 'All related documents will be deleted',
|
55 |
| - 'restrict' = 'Document can not be deleted' |
| 55 | + 'restrict' = 'Document cannot be deleted' |
56 | 56 | }
|
57 | 57 |
|
58 | 58 | $: 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')) |
60 | 69 | ) as Models.AttributeRelationship[];
|
61 | 70 | </script>
|
62 | 71 |
|
|
0 commit comments