Back

Pagination in relationships

  • 0
  • Self Hosted
  • Flutter
  • Databases
  • Web
Kv
30 Nov, 2023, 06:12

Posts and Comments are my two collections. In the Post collection, I created a two-way - one-to-many relationship so that I may retrieve all associated comments when I getDocument or listDocuments from the Posts collection. Consider the following scenario: A single post has 100 related comments. Is it possible to paginate relationships such that I only get the 3 most recent related comments when I get or list posts?

TL;DR
Pagination queries for relationships are not currently supported in Appwrite. However, you can achieve pagination by modifying your data structure. Instead of having a direct relationship between posts and comments, you can create a separate collection for comments and use a reference field to link each comment to a post. Then, you can use pagination queries on the comments collection to retrieve the desired number of recent comments for each post.
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