Aboud
Aboud
DTDrizzle Team
Created by Aboud on 2/22/2024 in #help
Defining a one-to-many relation within the same table?
I have a Postgres table phone_call and need to define a one-to-many relation between a row and other rows in the table:
export const phone_call = pgTable("phone_call", {
id: text("id").primaryKey().notNull(),
parent_id: text("parent_id"), // if null, the this is a parent, otherwise a child call
owner_id: varchar("owner_id", { length: 20 }).notNull(),
//...
});
export const phone_call = pgTable("phone_call", {
id: text("id").primaryKey().notNull(),
parent_id: text("parent_id"), // if null, the this is a parent, otherwise a child call
owner_id: varchar("owner_id", { length: 20 }).notNull(),
//...
});
export const phoneCallRelations = relations(schema.phone_call, ({ one, many }) => ({
owner: one(schema.user, {
fields: [schema.phone_call.owner_id],
references: [schema.user.id],
}),
parent: one(schema.phone_call, {
fields: [schema.phone_call.parent_id],
references: [schema.phone_call.id],
}),
children: many(schema.phone_call),
}));
export const phoneCallRelations = relations(schema.phone_call, ({ one, many }) => ({
owner: one(schema.user, {
fields: [schema.phone_call.owner_id],
references: [schema.user.id],
}),
parent: one(schema.phone_call, {
fields: [schema.phone_call.parent_id],
references: [schema.phone_call.id],
}),
children: many(schema.phone_call),
}));
When I query findMany with parent, it works, but when I do a with children, it doesn't. No problem with 1-to-M across tables... but within the same table is there a way to do this? Much appreciated!
1 replies
DTDrizzle Team
Created by Aboud on 10/31/2023 in #help
Drizzle with NextJS 13/14 revalidateTag ?
Hey everyone, has anyone tried passing tags to Drizzle db client to work with NextJS 13/14 revalidateTag ? I'm querying in an RSC. It works with fetch API calls, but was wondering if Drizzle or an clients (I'm using neon serverless) have fetch under the hood and a way to pass { next: tags: ['mytag'] } options in...
1 replies