drizzle-team / drizzle-team/drizzle-orm

[BUG]: Relations inconsistent to what defined in schema and what is generated.

Open
#2,499 0 comments 0 reactions 0 assignees View on GitHub
bug drizzle/kit priority rqb
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.31.2

### What version of `drizzle-kit` are you using?

0.22.4

### Describe the Bug

Inconsistencies of what was defined in schema vs what is generated.

Following was defined.

```

export const UserRoleTable = pgTable("UserRole", {
role: text("role").unique().notNull().primaryKey(),
});

export const UserTable = pgTable("User", {
id: uuid("id").primaryKey().defaultRandom().notNull(),
name: text("name"),
lastName: text("lastName"),
email: text("email").notNull().unique(),
emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image"),
password: text("password"),
role: text("role").notNull().default("USER"),
isTwoFactorEnabled: boolean("isTwoFactorEnabled").default(false).notNull(),
});
export const UserRoleRelations = relations(UserRoleTable, ({ many }) => ({
Users: many(UserTable),
}));

export const UserRelations = relations(UserTable, ({ many, one }) => ({
Accounts: many(AccountTable),
sessions: many(SessionTable),
TwoFactorConfirmations: many(TwoFactorConfirmationTable),
role: one(UserRoleTable, {
fields: [UserTable.role],
references: [UserRoleTable.role],
}),
}));

```

Check how User relations have been generated twice for role.

```

export const userRelations = relations(user, ({ one, many }) => ({
accounts: many(account),
sessions: many(session),
twoFactorConfirmations: many(twoFactorConfirmation),
userRoles: many(userRole, {
relationName: "userRole_role_user_role",
}),
userRole: one(userRole, {
fields: [user.role],
references: [userRole.role],
relationName: "user_role_userRole_role",
}),
}));

```

### Expected behavior

To have consistensies in relation shema generated.

### Environment & setup

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.