PierreP
Convex Communityโ€ข2y agoโ€ข
5 replies
Pierre

Pagination and Self-Reference

Let's say two users can be friends. To model this, I used the following approach:

const users = defineTable({ ... })

const friendsRelationships = defineTable({
  user1Id: v.id("users"),
  user2Id: v.id("users")

Then user1Id and user2Id can be populated by some user Ids.

However, what if I want to retrieve all the friends of a given user that are paginated. Given a user id can either be in user1Id or user2Id it looks like this is not possible with the current approach.
As an alternative, we could duplicate all the relationships and swap user1Id and user2Id so that I can paginate by indexing user1Id or user2Id, but this doesn't look optimal to duplicate those in the same table.
Was this page helpful?