foreignKey function options

foreignKey({
columns: [table.orgId, table.topicName],
foreignColumns: [topics.orgId, topics.name],
}),
foreignKey({
columns: [table.orgId, table.topicName],
foreignColumns: [topics.orgId, topics.name],
}),
how can I add onDelete option if I have composite foreignKey constraint?
1 Reply
Levitybot
Levitybot4d ago
Hi scape, I'm very new to Drizzle, but this is what I'm currently working with, hope it helps export const location = pgTable( 'location', { id: serial('id').primaryKey(), name: text('name').notNull(), companyId: integer('company_id').notNull() }, (t) => [ foreignKey({ name: 'company_has_locations_fk', columns: [t.companyId], foreignColumns: [company.id] }).onDelete('cascade') ] ); export const locationRelations = relations(location, ({ one }) => ({ company: one(company, { fields: [location.companyId], references: [company.id], relationName: 'company_has_locations' }) })); export type Location = typeof location.$inferSelect;

Did you find this page helpful?