Back

How do I use query?

  • 0
  • Databases
  • Flutter
laurencetroyv
12 Nov, 2023, 12:30

I have these three collections namely users, schools, and assignment. The assignment collection has a relationship to school and user mainly one to many (one school/user, many assignment) relationships. How do I query all schools that have been assigned to that assignment?

TL;DR
The user is trying to figure out how to query all schools that have been assigned to an assignment. They already know how to find assignments for a specific user, but are unsure about retrieving the corresponding schools. A workaround suggested is to include the school ID in the assignments collection and query against it. Another option is to fetch all data from the database and filter it out in the code. Unfortunately, queries on relationships are not currently supported.
Drake
12 Nov, 2023, 22:05

Queries on relationships are not supported at the moment

laurencetroyv
13 Nov, 2023, 13:52

ohh okay, I guess I'll just fetch all data from the db then filter it out my code. thank you

Drake
13 Nov, 2023, 15:32

A workaround could be to include the school ID in the assignments collection and then query against that

laurencetroyv
14 Nov, 2023, 08:27

I already have that, the assignments collection contain attributes of user and schools but how can I get all the schools that is assigned to an assignment?

for example I have this 9 assignments with different school ID and linked to a user how can I query that?

finding the assignments that assigned on the user can be using Query.equal("user", [user_id]). but how do I only get all schools that has been assigned to the user in the assignment collection?\

Drake
14 Nov, 2023, 17:57

that query should give you all assignments where user == user_id...and so each of those assignments has a school. so what part are you stuck on?

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