Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: 1:1 relation ends up with extra "many" column — SQLite #2862

Open
bitofbreeze opened this issue Aug 27, 2024 · 0 comments
Open

[BUG]: 1:1 relation ends up with extra "many" column — SQLite #2862

bitofbreeze opened this issue Aug 27, 2024 · 0 comments
Labels
bug Something isn't working db/sqlite drizzle/studio Issues related to Drizzle Studio

Comments

@bitofbreeze
Copy link

bitofbreeze commented Aug 27, 2024

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:

image image

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

@bitofbreeze bitofbreeze added the bug Something isn't working label Aug 27, 2024
@bitofbreeze bitofbreeze changed the title [BUG]: 1:1 relation ends up with extra "many" column [BUG]: 1:1 relation ends up with extra "many" column with SQLite Aug 27, 2024
@bitofbreeze bitofbreeze changed the title [BUG]: 1:1 relation ends up with extra "many" column with SQLite [BUG]: 1:1 relation ends up with extra "many" column — SQLite Aug 27, 2024
@L-Mario564 L-Mario564 added db/sqlite drizzle/studio Issues related to Drizzle Studio labels Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working db/sqlite drizzle/studio Issues related to Drizzle Studio
Projects
None yet
Development

No branches or pull requests

2 participants