Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report: Cannot query for relation field in a document #7302

Open
2 tasks done
vuggy17 opened this issue Dec 18, 2023 · 3 comments
Open
2 tasks done

🐛 Bug Report: Cannot query for relation field in a document #7302

vuggy17 opened this issue Dec 18, 2023 · 3 comments
Labels
bug Something isn't working feature / relationships Fixes and upgrades for database relationships product / databases Fixes and upgrades for the Appwrite Database.

Comments

@vuggy17
Copy link

vuggy17 commented Dec 18, 2023

👟 Reproduction steps

  • Create a document using App write console
    image

  • Query for that document using node-appwrite sdk

  async getMyRooms(myId: string) {
    try {
      const { documents } =
        await this.appwriteAdmin.database.listDocuments(
          AppWriteProvider.defaultDatabaseId, // "<my database id>"
          AppWriteProvider.projectDbCollections.chat.room, // "rooms"
          [Query.equal('members', [myId])],
        );

      return documents.map((doc) => new RoomEntity(doc));
    } catch (error) {
      console.log(error);
    }
  }

👍 Expected behavior

  • Document returned and not raise an error

👎 Actual Behavior

  • An error raised

In backend console:

AppwriteException [Error]: Server Error
    at Client.call (E:\projects\idle\node_modules\.pnpm\[email protected]\node_modules\node-appwrite\lib\client.js:174:31)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Databases.listDocuments (E:\projects\idle\node_modules\.pnpm\[email protected]\node_modules\node-appwrite\lib\services\databases.js:1638:16)
    at RoomRepositoryImpl.getMyRooms (E:\projects\idle\dist\apps\idle.api\webpack:\src\modules\room\repository.ts:45:9) {
  code: 500,
  type: 'general_unknown',
  response: {
    message: 'Server Error',
    code: 500,
    type: 'general_unknown',
    version: '1.4.13'
  }
}

In docker, using docker logs appwrite

[Error] Method: GET
[Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents
[Error] Type: PDOException
[Error] Message: Unknown column 'members' in 'where clause'
[Error] File: @swoole-src/library/core/Database/PDOStatementProxy.php
[Error] Line: 62

🎲 Appwrite version

Version 1.4.x

💻 Operating system

Windows

🧱 Your Environment

I'm using
"node-appwrite": "^11.0.0",

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@vuggy17 vuggy17 added the bug Something isn't working label Dec 18, 2023
@vuggy17
Copy link
Author

vuggy17 commented Dec 18, 2023

Here is my collection attributes
image

image

@gepd
Copy link
Contributor

gepd commented Dec 18, 2023

Currently there is no support for queries with relationships

https://appwrite.io/docs/products/databases/relationships#queries

@vuggy17
Copy link
Author

vuggy17 commented Dec 19, 2023

@gepd, thank you for spending your time,
Is there any chance query works on fields which is not an array? I notice that the following snippet won't throw.

 async findFriendRequest(
    sender: ID,
    receiver: ID,
  ): Promise<FriendRequestEntity | null> {
    const { total, documents } =
      await this._appwriteAdmin.database.listDocuments(
        AppWriteProvider.defaultDatabaseId, // <my database id>
        AppWriteProvider.projectDbCollections.chat.friendInvitation, // friend-invitations 
        [Query.equal('receiver', receiver), Query.equal('sender', sender)],
      );

    if (total === 0) {
      return null;
    }
    return new FriendRequestEntity(documents[0]);
  }

Here is the collection:
image

image

image

@stnguyen90 stnguyen90 added product / databases Fixes and upgrades for the Appwrite Database. feature / relationships Fixes and upgrades for database relationships labels Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature / relationships Fixes and upgrades for database relationships product / databases Fixes and upgrades for the Appwrite Database.
Projects
None yet
Development

No branches or pull requests

3 participants