© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
4 replies
laxels

TypeScript error when specifying `relationName` in a one-to-one relation

Hi there! I have the following relations:

export const userRelations = relations(user, ({ one }) => ({
  // TypeScript Error: Argument of type `{relationName: string}` is not assignable to parameter of type ...
  referralCode: one(referralCode, { relationName: `claimedBy` })
}));

export const referralCodeRelations = relations(referralCode, ({ one }) => ({
  createdBy: one(user, {
    fields: [referralCode.createdById],
    references: [user.id],
    relationName: `createdBy`
  }),
  claimedBy: one(user, {
    fields: [referralCode.claimedById],
    references: [user.id],
    relationName: `claimedBy`
  })
}));
export const userRelations = relations(user, ({ one }) => ({
  // TypeScript Error: Argument of type `{relationName: string}` is not assignable to parameter of type ...
  referralCode: one(referralCode, { relationName: `claimedBy` })
}));

export const referralCodeRelations = relations(referralCode, ({ one }) => ({
  createdBy: one(user, {
    fields: [referralCode.createdById],
    references: [user.id],
    relationName: `createdBy`
  }),
  claimedBy: one(user, {
    fields: [referralCode.claimedById],
    references: [user.id],
    relationName: `claimedBy`
  })
}));


The example code shows a case where the
referralCode
referralCode
table has 2 fields that reference the
user
user
table, so specifying
relationName
relationName
is required to disambiguate. However, the config object taken by the
one
one
function requires the
fields
fields
and
references
references
properties, which doesn't make sense for the
user
user
table which does not have foreign key fields.

For some reason, the
many
many
function does not have this problem, and specifying just
relationName
relationName
is fine.

Please let me know if I'm doing something wrong here.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

one-to-many relation - multiple relations
Drizzle TeamDTDrizzle Team / help
3y ago
Optional One-to-One Relation
Drizzle TeamDTDrizzle Team / help
3y ago
explain relationName please
Drizzle TeamDTDrizzle Team / help
3y ago
[Relational Queries] Nullable one-to-one relationship
Drizzle TeamDTDrizzle Team / help
3y ago