drainpixie
drainpixie
DTDrizzle Team
Created by drainpixie on 10/14/2024 in #help
Can't create relation between two tables
I'm trying to create a relation between a clients table and a sheets tables where a client can have multiple sheets linked to their ID, but I keep getting complaints about incompatible foreign keys due to my bad schema Fixed; for anyone wondering, instead of using references(() => clients.id) very shallowly you have to create proper relations like such:
export const clientsRelations = relations(clients, (({ many }) => ({
sheets: many(sheets),
})))

export const sheetsRelations = relations(sheets, (({ one }) => ({
client: one(clients, {
fields: [sheets.client_id],
references: [clients.id],
})
})))
export const clientsRelations = relations(clients, (({ many }) => ({
sheets: many(sheets),
})))

export const sheetsRelations = relations(sheets, (({ one }) => ({
client: one(clients, {
fields: [sheets.client_id],
references: [clients.id],
})
})))
ù
1 replies