Back

Get each post's user details together with the posts when I get all posts

  • 0
  • Web
Nikky
4 Sep, 2023, 06:43

I have a Post collection with reference to User collection using userId. When I get all post, is there a way to automatically get user's details as well for each post? Im using Client SDK and Cloud.

TL;DR
The user wants to automatically retrieve user details along with posts when getting all posts. They are concerned about hitting the request limit and ask if making sequential requests to get user details will be counted towards the limit. The response suggests creating a separate users collection and using a relationship field in the posts collection to connect posts to authors. It is mentioned that self-hosted or waiting for cloud support is needed to connect posts to author collections. The user also asks about implementing other features such as posts with images and user info, saved posts, and user groups. The response advises using Appwrite teams for user groups and suggests creating a complex app using a combination
Binyamin
4 Sep, 2023, 16:34

Not for now (it's not available in the self-hosted version as well) For this use case it will be a bit complex

  • either move the whole logic to a cloud function (which can be overwhelming)
  • make a sequential request to get user details
Nikky
5 Sep, 2023, 01:15

Hey @Binyamin , if I install server SDK and set the relationship programmatically. Will it work for my use case?

Nikky
5 Sep, 2023, 01:16

Im about to try this. But As I read your reply, would like to double check. https://appwrite.io/docs/databases-relationships#create-in-code

Binyamin
5 Sep, 2023, 01:20

Relationship won't work as you're working with the cloud

Nikky
5 Sep, 2023, 01:23

I see... I need self-hosted for it to work? What combination of AppWrite tools or setup would you suggest so I can create a complex App with AppWrite?

Do you have links to some repo that implements complex CRUD using React/Next? Would really appreciate it. πŸ™

Nikky
5 Sep, 2023, 01:30

Some features Im looking to try to implement with Appwrite:

  • Posts with image and user info (CRUD) - there will be a lot of posts so creating new request to get user info for each post might not be ideal.
  • Saved posts
  • User groups
Binyamin
5 Sep, 2023, 02:27

Notes:

  • In self hosted you'll solve only the for the first part, the relationship, but for the second part - user to collection relationship this is not available right now in any version.
  • If you need to connect posts to author collection, then in this case I would recommend going with self-hosted or wait for the cloud to support relationships.
  • For the React part I recommend checking the react at awesome-appwrite

Structure:

You can do something like this. Create another users collection, in add all of your user details, create a function that will get trigger each time new user is created or edited, then you can update that users collection with ease. In the posts collection add user_id relationship field of many to one to the users collection. For user groups the best would be to use Appwrite teams

Nikky
5 Sep, 2023, 02:51

I see gotcha! Thanks @Binyamin πŸ™

Nikky
5 Sep, 2023, 07:24

Hey @Binyamin if I go this path - "make a sequential request to get user details", will I hit request limit? I encounter request limit last time. Im not sure if this type of request is not counted on that.

Binyamin
6 Sep, 2023, 00:34

You'll probably hit it yes. To avoid that you'll have to use function

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