many-to-may relation

How do i define relation like a post probably has many comments that nested, for example a person can reply to other person's comment,
export const comments = mysqlTable(
'comments',{
id: serial('id').primaryKey(),
postId: int('post_id'),
comment: text('content').notNull(),
authorId: int('author_Id').notNull(),
parentId: int('parent_id'),
likes: int('likes').default(0),
},

);
export const comments = mysqlTable(
'comments',{
id: serial('id').primaryKey(),
postId: int('post_id'),
comment: text('content').notNull(),
authorId: int('author_Id').notNull(),
parentId: int('parent_id'),
likes: int('likes').default(0),
},

);
4 Replies
Angelelz
Angelelz14mo ago
See here, specially the part where it talks about self relation: https://orm.drizzle.team/docs/indexes-constraints#foreign-key
Thogn
Thogn14mo ago
I'm using planetscale which does not alow foregn-key, Is there any way to solve this ?
Adrastus
Adrastus14mo ago
Operating without foreign key constraints
How to manage your relational data without formal foreign key constraints in your schema
Want results from more Discord servers?
Add your server