Back

[CLOSED] Query Select in relationshiop

  • 0
  • Databases
  • Flutter
Mosh Ontong
14 Apr, 2023, 05:41

How to query select only the child collection's id

For example

Vocabulary -> language vocabulary can contain one language

language can belong to many vocabulary

So I want to select only the language id, I do not want to select all attributes of language when I query my vocabulary

TL;DR
User is having an issue with using Query.select in relationships within Appwrite. They want to select only the id attribute of the language collection, but it's not working as expected. There is currently no solution mentioned, but the user is told that internal attributes will always be returned and they can only specify their custom attributes using Query.select. The issue has been raised for internal discussion.
joeyouss
14 Apr, 2023, 05:54

Hi - is it just regarding relationships? https://appwrite.io/docs/databases-relationships#query

Mosh Ontong
14 Apr, 2023, 06:25

Yes, it is.

But I think there is a problem on using the Query Select in flutter.

Without using the Query.select

TypeScript
      final documents = await databases.listDocuments(
          databaseId: kDatabaseId,
          collectionId: kVocabularyCollectionId,
          queries: [
            Query.equal("language", languageSelected.languageId),
          ]);

Now this is the output:

Mosh Ontong
14 Apr, 2023, 06:25
Mosh Ontong
14 Apr, 2023, 06:26

it contains the language collection's document

Mosh Ontong
14 Apr, 2023, 06:26

But what I want is to select only the language's id

Mosh Ontong
14 Apr, 2023, 06:28

therefore I am using the Query.select,

I try these all code:

  1. Query.select(['language.\$id']) -> not working
  2. Query.select(['\$id']) -> not working
  3. Query.select([]) -> it is working but weird?
Mosh Ontong
14 Apr, 2023, 06:29

This is the output when I am using the number 3. It is weird right?

joeyouss
14 Apr, 2023, 09:45

currently appwrite gives you every internal attribute always, no matter what you select. With select query, you can specify which YOUR attribute you want to get. But internal ones starting with $, you always get those.

Mosh Ontong
14 Apr, 2023, 10:42

I did not get it Ms. @joeyouss In instance, Vocabulary have relationship in Language Collection. Hence, it is expected when getting those documents in Vocabulary collection, the language collection will be included in payload. Now my question is that, how can I Select query only the id attribute of Language collection.

Guille
14 Apr, 2023, 14:25

you can't perform any query filter on relationship field (child) you only can add queries to the parent collection, You can't limit the quantity of items or something similar.

Seems like that queries will be released in the next version

Guille
14 Apr, 2023, 14:27
TypeScript
I try these all code:
1. Query.select(['language.\$id']) -> not working
2. Query.select(['\$id']) -> not working
3. Query.select([]) -> it is working but weird?

This 3 filters are acting in the vocabulary collection not in language

Mosh Ontong
14 Apr, 2023, 14:28

Yeah but it is weird without using the Query.select, it gives me the whole data of my language. If I am using the Query.select, it only gives me the id of my language.

Guille
14 Apr, 2023, 14:30

πŸ€”

Guille
14 Apr, 2023, 14:32

maybe I'm not understanding well but I see all items in the data Map including language, how is before your filter, I see the last image is the output with Query.select([]) but what is the output without it?

Mosh Ontong
14 Apr, 2023, 14:36

this one

Guille
14 Apr, 2023, 14:43

I see the difference now, maybe someone of the team can clarify this @Meldiron (sorry to ping you) do you now what could be happen here? it seems like that is working but isn't something documented

Meldiron
14 Apr, 2023, 15:58

Hey there @Mosh Ontong πŸ‘‹ To answer:

But what I want is to select only the language's id

It seems like a valid concerned, and I opened this to internal discussion. As of Appwrite 1.3.1, inside Query.select, you should only specify your custom attributes. Internal attribudes such as ID, collectionId, databaseId, permissions, createdAt and updatedAt will always be returned. We noticed this can be annoying and defeat purpose of select query. We initially let those internal attributes there to make offline support possible in future. Thanks to feedback such as yours, we can think about it a bit more to provide better developer experience :appwritepeepo:

Regarding normal select and select with relationships, they should work exactly the same. And for selecting data inside relation, you use . in between names. Sooo in your scenario doing Query.select(['language.$id']) would be the right approach. Again, sadly, this wont work as of right now. Buuut your thread started internal discussion πŸ˜‡

Drake
14 Apr, 2023, 16:42

@Mosh Ontong it would be great if you could create a GitHub issue for this so that the request doesn't get lost and others can πŸ‘πŸΌ it

Mosh Ontong
14 Apr, 2023, 17:05
joeyouss
14 Apr, 2023, 17:19

[CLOSED] Query Select in relationshiop

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more