foreignKey function options
how can I add onDelete option if I have composite foreignKey constraint?
1 Reply
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;