From de864c6809458e31c20b6b3a67206aac32e0615b Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Thu, 18 May 2023 07:41:34 -0700 Subject: [PATCH] WIP: Ensure related document shows in Console --- .../attributes/relationship.svelte | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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 f01e54ca58..710efe4e63 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 @@ -57,20 +57,39 @@ }); async function getDocuments(search: string = null) { + const documentList = { + total: 0, + documents: [] + }; + + if (value) { + if (isRelationshipToMany(attribute)) { + documentList.documents.concat($doc[attribute.key]); + documentList.total += $doc[attribute.key].length; + } else { + documentList.documents.push($doc[attribute.key]); + documentList.total += 1; + } + } + if (search) { const documents = await sdk.forProject.databases.listDocuments( databaseId, attribute.relatedCollection, - [Query.search('$id', search), Query.orderDesc('$createdAt')] + [`startsWith("$id", "${search}")`, Query.orderDesc('$createdAt')] ); - return documents; + documentList.documents.concat(documents.documents); + documentList.total += documents.total; } else { const documents = await sdk.forProject.databases.listDocuments( databaseId, attribute.relatedCollection ); - return documents; + documentList.documents.concat(documents.documents); + documentList.total += documents.total; } + + return documentList; } //Reactive statements