drizzle-team / drizzle-team/drizzle-orm
[BUG]: 1:1 relation ends up with extra "many" column — SQLite
- 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.33.0
### What version of `drizzle-kit` are you using?
0.24.2
### Describe the Bug
The following code is meant to create a simple 1:1 relation where user has a stripe account and stripe account has a user. However, stripe account ends up having a "users" column in addition to the "user" column:
The extra "users" column does not work. Querying it with
```
db.query.stripeAccount.findFirst({
with: {
users: true
}
})
```
gives the error `There is not enough information to infer relation "stripeAccount.users"`. Querying the "user" column works normally.
Here's the code:
```
import { relations } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
export const userTable = sqliteTable("user", {
id: integer("id").primaryKey(),
stripeAccountId: text("stripe_account_id").references(
() => stripeAccountTable.id,
{ onDelete: "cascade" },
),
});
export const stripeAccountTable = sqliteTable("stripe_account", {
id: text("id").primaryKey(),
});
export const userRelations = relations(userTable, ({ one }) => ({
stripeAccount: one(stripeAccountTable, {
fields: [userTable.stripeAccountId],
references: [stripeAccountTable.id],
}),
}));
export const stripeAccountRelations = relations(
stripeAccountTable,
({ one }) => ({
user: one(userTable, {
fields: [stripeAccountTable.id],
references: [userTable.stripeAccountId],
}),
}),
);
```
### Expected behavior
Stripe account to only have one relational column called "user".
### Environment & setup
```
driver: "turso"
dialect: "sqlite"
```
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.