Web Dev Cody
Web Dev Cody14mo ago

model relationships, are there benefits to using v.id?

I have a simple schema
import { defineSchema, defineTable } from 'convex/server';
import { v } from 'convex/values';

export default defineSchema({
plans: defineTable({
userId: v.string(),
idea: v.string(),
targetUser: v.string(),
plan: v.any(),
version: v.number(),
}),
users: defineTable({
userId: v.string(),
credits: v.number(),
}),
});
import { defineSchema, defineTable } from 'convex/server';
import { v } from 'convex/values';

export default defineSchema({
plans: defineTable({
userId: v.string(),
idea: v.string(),
targetUser: v.string(),
plan: v.any(),
version: v.number(),
}),
users: defineTable({
userId: v.string(),
credits: v.number(),
}),
});
I'm curious if there is a performance benefit to instead have the userId on plan be v.id("plans") or if this approach will basically work the same (assuming I add an index)?
2 Replies
Web Dev Cody
Web Dev CodyOP14mo ago
the reason I'm doing this, is because on my clerk session, I only have access to the clerk's userId which makes it a lot easier to just filter by userId on plans instead of having to first look up the user, get the _id, then query by plans
ballingt
ballingt14mo ago
There are no advantages here besides that the index on _id is already there and can't be disabled. Creating your own identifier like this absolutely makes sense as long as you use an index.

Did you find this page helpful?