Is it possible to do circular dependencies between tables? #396
-
In mikro-orm I can import entity as type. How can I do this with drizzle-orm? import { index, integer, pgTable, serial, varchar } from 'drizzle-orm/pg-core';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
fullName: varchar('full_name', { length: 256 }),
// FIXME: how can I do this??
authOtpId: integer('auth_otp_id').references(() => authOtps.id),
}, (users) => ({
nameIdx: index('name_idx').on(users.fullName),
}));
export const authOtps = pgTable('auth_otp', {
id: serial('id').primaryKey(),
phone: varchar('phone', { length: 256 }),
userId: integer('user_id').references(() => users.id),
}); |
Beta Was this translation helpful? Give feedback.
Answered by
AndriiSherman
Apr 7, 2023
Replies: 1 comment 4 replies
-
@mkieblesz Yes! export const users = pgTable(
"users",
{
id: serial("id").primaryKey(),
fullName: varchar("full_name", { length: 256 }),
authOtpId: integer("auth_otp_id")
},
(users) => ({
nameIdx: index("name_idx").on(users.fullName),
fk: foreignKey({
columns: [users.authOtpId],
foreignColumns: [authOtps.id],
}),
})
);
export const authOtps = pgTable("auth_otp", {
id: serial("id").primaryKey(),
phone: varchar("phone", { length: 256 }),
userId: integer("user_id").references((): AnyPgColumn => users.id),
}); |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
AndriiSherman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mkieblesz Yes!