ViperV
Convex Community3mo ago
2 replies
Viper

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"]),
});


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"]),


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 ?
Was this page helpful?