A typical workflow with ORMs is to, for example, fetch an item from the DB and include the user who created it. How would I do that with AppWrite? Is that easily available in the docs somewhere?
Here's an example:
const response = await databases.getDocument(
DATABASE_ID,
BOOKS_COLLECTION_ID,
id,
// Maybe I should add some sort of query here?
)
Also, do I need to create a table on the DB to fetch info on other users?
You need to have an attribute representing the creator of the doc.
Could you share more details about your usecases?
For now, it's as simple as it gets. I have users, each user can create a book (which consists of a title, description, and the author's ID). Then, when a user click's on a book's page, I would like to show the book itself, as well as its author's username. It should be equivalent to a simple SQL JOIN.
Drizzle and Prisma both have that sort of thing in their docs, but I haven't been able to find it on Appwrite yet.
I did create a second table for user data, replicating and extending the auth data.
You could use relationship But doing it with saving the id of the author/user in the book document will be far more stable.
Fetch the doc using query.equal of userid with the creator id in your books collection
I do save the author's id in the book document.
How do I do that in the JS package?
const response = await databases.listDocument(
DATABASE_ID,
BOOKS_COLLECTION_ID,
[
Query.equal('Author':['name']),
]
)
By default there will be upto 25 docuement present if condition meets You could decrease or increase using Query.limit
Check out here for more details
I don't think that's what I want actually. That's a filter, what I'm looking for is a JOIN statement equivalent between 2 tables. That sort of thing only tackles 1 table.
There is no Join Eq. https://appwrite.io/threads/1326625067022684305
That's so essential to these sorts of products though. Very strange. It should be kinda like the first thing on a feature list priority queue, I believe.
You could make a feature request in github 🤷♂️.
How do they plan on dealing with that sort of issue. Do they plan on implementing joins at some point? Do they have an alternative solution? Is this how it's going to be forever?
The best i can say is if The Join feature request is more wanted by users then it might be added in the future version But currently the way is to establish a link via atrribute
Recommended threads
- Free plan Usage
I using a free plan with one organization. I have three projects but on the free plan I should be able to have 2 projects running But in my case only 1 out of ...
- Subscription Problem
I'm making an app in RN with Expo and Appwrite and there's a functionality which allows the user to create a task/test (i'll be reffering to them collectively a...
- Database AI Column Suggestion Use Case
I tried using the AI column suggestion feature. For me, I prefer writing my column design separately in a notepad. Then my intention is to paste it into the AI ...