Marcel
Marcel
DTDrizzle Team
Created by Marcel on 10/25/2024 in #help
How to declare optional one-to-one relationship
UPDATE: Just realized that if I omit the field information from usersRelations, it will infer profile relationship correctly to Profile | null.
// new relations variables
export const usersRelations = relations(users, ({ one }) => ({
profile: one(profiles),
}))

export const profilesRelations = relations(profiles, ({ one }) => ({
user: one(users, {
fields: [profiles.userId],
references: [users.id]
}),
}))
// new relations variables
export const usersRelations = relations(users, ({ one }) => ({
profile: one(profiles),
}))

export const profilesRelations = relations(profiles, ({ one }) => ({
user: one(users, {
fields: [profiles.userId],
references: [users.id]
}),
}))
Please let me know if I should close this
2 replies