Skip to content

fix: generate one() instead of many() for one-to-one relations with unique FK#5480

Open
Jah-yee wants to merge 1 commit intodrizzle-team:mainfrom
Jah-yee:fix/relations-unique-check
Open

fix: generate one() instead of many() for one-to-one relations with unique FK#5480
Jah-yee wants to merge 1 commit intodrizzle-team:mainfrom
Jah-yee:fix/relations-unique-check

Conversation

@Jah-yee
Copy link

@Jah-yee Jah-yee commented Mar 13, 2026

When a foreign key column has a UNIQUE constraint, the reverse relation should be one() instead of many(), representing a one-to-one relationship.

This fixes the issue where drizzle-kit pull generated many() for the reverse side of one-to-one relationships when the FK column has a UNIQUE constraint.

Before:

export const usersRelations = relations(users, ({ many }) => ({
  profiles: many(profiles), // incorrect - should be one()
}));

After:

export const usersRelations = relations(users, ({ one }) => ({
  profile: one(profiles), // correct for one-to-one
}));

Fixes #5478

…nique FK

When a foreign key column has a UNIQUE constraint, the reverse relation
should be one() instead of many(), representing a one-to-one relationship.

This fixes the issue where drizzle-kit pull generated many() for the reverse
side of one-to-one relationships when the FK column has a UNIQUE constraint.

Fixes drizzle-team#5478
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: drizzle-kit pull generates many() instead of one() for one-to-one relations (unique FK columns)

1 participant