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