Viper
Viper3w ago

Relation between App Schema and Component Schema (betterAuth)

So I am having hard times grasping that , I have convex/schema.ts which has the following
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
import type { Id } from "./betterAuth/_generated/dataModel";


export default defineSchema({
guest_book: defineTable({
// userId: v.string(),
// userId: v.id("user"),

content: v.string(),

createdAt: v.number(),
updatedAt: v.number(),
})
.index("by_user", ["userId"])

.index("by_date", ["createdAt"]),
});
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
import type { Id } from "./betterAuth/_generated/dataModel";


export default defineSchema({
guest_book: defineTable({
// userId: v.string(),
// userId: v.id("user"),

content: v.string(),

createdAt: v.number(),
updatedAt: v.number(),
})
.index("by_user", ["userId"])

.index("by_date", ["createdAt"]),
});
and i have convex/betterAuth/schema.ts which has a table called user with the userId
user: defineTable({
name: v.string(),
email: v.string(),
emailVerified: v.boolean(),
image: v.optional(v.union(v.null(), v.string())),
createdAt: v.number(),
updatedAt: v.number(),
userId: v.optional(v.union(v.null(), v.string())),
role: v.string(),
})
.index("email_name", ["email", "name"])
.index("name", ["name"])
.index("userId", ["userId"]),
user: defineTable({
name: v.string(),
email: v.string(),
emailVerified: v.boolean(),
image: v.optional(v.union(v.null(), v.string())),
createdAt: v.number(),
updatedAt: v.number(),
userId: v.optional(v.union(v.null(), v.string())),
role: v.string(),
})
.index("email_name", ["email", "name"])
.index("name", ["name"])
.index("userId", ["userId"]),
how can i make a relation between the guest_book and the user in the guestbook_schema I commented out the section for the userId in the guestbook_schema if I use v.string() it works but no relation , it is just a field i will have to programatically inject the userId I can't use v.id("user") since i will since it won't match schema validator , so is that possible to make relation between base app and components ?
2 Replies
Convex Bot
Convex Bot3w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart3w ago
If you don't have your own user table, the userId field in the better auth user table should be empty, you would just use the _id of the better auth user for all relations.

Did you find this page helpful?