grez72
grez72
CCConvex Community
Created by grez72 on 8/10/2024 in #support-community
native join
Given that it is possible to add relations to a document, is there a plan for convexdb to introduce a join operation? e.g., something like the following to efficiently retrieve a document and associated documents (further specifying which document fields to include to avoid over fetching).
const myPostsWithCommentsAndCommenterInfo = await ctx.db
.query("posts")
.withIndex("by_id_creator", q=> q.eq("id_creator", args.id_me))
.join("comments").on("posts", "id_comment").as("comment")
.join("users").on("comment", "id_user").as("comment_by").includes(["username", "profile_photo"])
.order("desc")
.paginate(args.paginationOpts)
const myPostsWithCommentsAndCommenterInfo = await ctx.db
.query("posts")
.withIndex("by_id_creator", q=> q.eq("id_creator", args.id_me))
.join("comments").on("posts", "id_comment").as("comment")
.join("users").on("comment", "id_user").as("comment_by").includes(["username", "profile_photo"])
.order("desc")
.paginate(args.paginationOpts)
Without this kind of built in support for joining documents, I'm not sure how to leverage the "relational" aspect of the document store. Given the current convex database query system, what would be the most efficient way to construct the full myPostsWithCommentsAndCommenterInfo document in the example above?
9 replies