diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/realtionship.ts b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/realtionship.ts new file mode 100644 index 000000000..8edc0b3ad --- /dev/null +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/realtionship.ts @@ -0,0 +1,11 @@ +import type { Models } from '@appwrite.io/console'; + +export function isRelationshipToMany(attribute: Models.AttributeRelationship) { + if (!attribute) return false; + const { side, relationType } = attribute || {}; + if (side === 'parent') { + return !['oneToOne', 'manyToOne'].includes(relationType); + } else { + return !['oneToOne', 'oneToMany'].includes(relationType); + } +} diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/relationship.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/relationship.svelte index 2af53d8f6..7d8196e70 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/relationship.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/document-[document]/attributes/relationship.svelte @@ -9,6 +9,7 @@ import { Query, type Models } from '@appwrite.io/console'; import { onMount } from 'svelte'; import { doc } from '../store'; + import { isRelationshipToMany } from './realtionship'; export let id: string; export let label: string; @@ -61,27 +62,25 @@ } } - function isArrayFunc() { - const { side, relationType } = attribute || {}; - if (side === 'parent') { - return !['oneToOne', 'manyToOne'].includes(relationType); - } else { - return !['oneToOne', 'oneToMany'].includes(relationType); - } - } - - $: isArray = isArrayFunc(); - // Reactive statements $: getDocuments(search).then((res) => (documentList = res)); - $: if (isArray) value = relatedList; + $: if (isRelationshipToMany(attribute)) value = relatedList; $: paginatedItems = relatedList.slice(offset, offset + limit); $: total = relatedList?.length; + $: options = + documentList?.documents?.map((n) => { + const data = displayNames.filter((name) => name !== '$id').map((name) => n?.[name]); + return { + value: n.$id, + label: n.$id, + data + }; + }) ?? []; -{#if editing && isArray && total > 0} +{#if editing && isRelationshipToMany(attribute) && total > 0}