© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago
alirezasoltan

nested query

1 : i want just get comments not have reply how do it and i want just get comments have reply :
2 : i want just get comments with storeId example 1 (have relation one to many product to comment and product have storeId) :
schema :
export const comments = pgTable("comments", {
id: serial("id").primaryKey(),
text: varchar("text", { length: 191 }),
createdAt: timestamp("createdAt").defaultNow(),
authorId: integer("authorId").notNull(),
productId: integer("productId").notNull(),
storeId: integer("storeId"),
isFaq: boolean("isFaq").notNull().default(false),
isOwner: boolean("isOwner").notNull().default(false),
})

export const replies = pgTable("replies", {
id: serial("id").primaryKey(),
text: varchar("text", { length: 191 }),
createdAt: timestamp("createdAt").defaultNow(),
authorId: integer("authorId").notNull(),
isOwner: boolean("isOwner").notNull().default(false),
commentId: integer("commentId").notNull(),
})
export const commentsRelations = relations(comments, ({ many, one }) => ({
commentVotes: many(commentVotes),
product: one(products, {
fields: [comments.productId],
references: [products.id],
}),
reply: many(replies)
}))

export const replyRelations = relations(replies, ({ many, one }) => ({
comments: one(comments, {
fields: [replies.commentId],
references: [comments.id],
}),
}))
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Help with nested query
Drizzle TeamDTDrizzle Team / help
2y ago
Query based on nested relation
Drizzle TeamDTDrizzle Team / help
2y ago
DEEPLY NESTED QUERY using { with }
Drizzle TeamDTDrizzle Team / help
2y ago
Select in nested findMany query ?
Drizzle TeamDTDrizzle Team / help
2y ago