Back

How can I filter the posts based on a relationship attribute?

  • 0
  • Cloud
Rohan
20 Jul, 2024, 08:23

Hello there,

I've a post collection and each post has a relationship with the user collection. I was trying to fetch all the posts by a particular user by using this query:

TypeScript
const documents = await databases.listDocuments(
    DATABASE_ID,
    COLLECTION_ID,
    [Query.equal("user.$id","userId")]
  );

But I'm getting this error:

TypeScript
⨯ node_modules/appwrite/dist/esm/sdk.js (428:26) @ Client.eval
AppwriteException: Invalid query: Cannot query nested attribute on: user
    at Generator.next (<anonymous>)

user attribute:

TypeScript
{
    otherPostAttributes,
    user: {
        $id: "123",
        name: "John Doe",
    }
}

I would like to know how can I achieve this? Any help is appreciated. Thanks

TL;DR
Developers are unable to filter posts by a relationship attribute. The query to fetch posts by a particular user is producing an error. The issue seems to be that queries currently do not work on relationships. Solution: Consider redesigning the database structure to allow for more direct querying, or find a workaround until queries on relationships are supported.
Joshi
20 Jul, 2024, 08:42

Querjes currently do not work on relationships

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