Yvens
Yvens9mo ago

Paginate many to many edge (ents)

Hello, I don't get how to paginate a many to many query on convex-ents:
const result = username === ""
? await ctx.table("organizations").getX(organizationId).edge("users")
: await ctx
.table("users")
.search("search_username", (q) => q.search("username", username).eq("organizationId", organizationId))
.paginate(paginationOpts);
return result;
const result = username === ""
? await ctx.table("organizations").getX(organizationId).edge("users")
: await ctx
.table("users")
.search("search_username", (q) => q.search("username", username).eq("organizationId", organizationId))
.paginate(paginationOpts);
return result;
` My problem is on this line :
await ctx.table("organizations").getX(organizationId).edge("users")
await ctx.table("organizations").getX(organizationId).edge("users")
``
6 Replies
Yvens
YvensOP9mo ago
For now I've done this as workaround:
await ctx.table("users").filter(q => q.eq(q.field("organizationId"), organizationId)).paginate(paginationOpts)
await ctx.table("users").filter(q => q.eq(q.field("organizationId"), organizationId)).paginate(paginationOpts)
`` But I had to add an organizationId field, and not use the edge
Michal Srb
Michal Srb9mo ago
It's not supported currently, I filed https://github.com/xixixao/convex-ents/issues/25 for it. You could hand roll it via ctx.db (you need to paginate the edge table).
GitHub
many:many edge cannot be paginated · Issue #25 · xixixao/convex-ents
This const result = await ctx .table("messages") .getX(messageId) .edge("tags") .paginate(paginationOpts); should paginate the underlying edge table before loading the ents on t...
Yvens
YvensOP9mo ago
Ok no problem, any thought on this workaround ?
await ctx.table("users").filter(q => q.eq(q.field("organizationId"), organizationId)).paginate(paginationOpts)
await ctx.table("users").filter(q => q.eq(q.field("organizationId"), organizationId)).paginate(paginationOpts)
` Thank you
Michal Srb
Michal Srb9mo ago
paginate is supported on 1:many edges, so since you wanted the end to be optional, another work around would be to a create a "sentinel" group, to which you assign all the users who don't have a group. For your workaround: Use an index
Yvens
YvensOP9mo ago
Yes ok thank you 🙏🏾
Michal Srb
Michal Srb6mo ago
@Yvens the pagination for many:many edges is now fixed in 0.9.0

Did you find this page helpful?