Issue With Defining References

Hello! I am attempting to define a reference to another table. I have the following users table:
export const users = pgTable("users", {
userID: serial("user_id").primaryKey(),
clerkID: text("clerk_id").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
role: text("role").notNull().default("member"),
});

export const usersRelations = relations(users, ({ one, many }) => ({
data: one(data, { fields: [users.userID], references: [data.userID] }),
}));

export const data = pgTable("data", {
userID: integer("user_id").primaryKey(),
// some other data in here
});
export const users = pgTable("users", {
userID: serial("user_id").primaryKey(),
clerkID: text("clerk_id").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
role: text("role").notNull().default("member"),
});

export const usersRelations = relations(users, ({ one, many }) => ({
data: one(data, { fields: [users.userID], references: [data.userID] }),
}));

export const data = pgTable("data", {
userID: integer("user_id").primaryKey(),
// some other data in here
});
however when update the tables to have the references like so
export const users = pgTable("users", {
userID: serial("user_id").primaryKey().references(() => data.userID),
clerkID: text("clerk_id").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
role: text("role").notNull().default("member"),
});

export const usersRelations = relations(users, ({ one, many }) => ({
data: one(data, { fields: [users.userID], references: [data.userID] }),
}));

export const data = pgTable("data", {
userID: integer("user_id").primaryKey().references(() => users.userID),
// some other data here
});
export const users = pgTable("users", {
userID: serial("user_id").primaryKey().references(() => data.userID),
clerkID: text("clerk_id").unique(),
firstName: text("first_name").notNull(),
lastName: text("last_name").notNull(),
email: text("email").notNull().unique(),
role: text("role").notNull().default("member"),
});

export const usersRelations = relations(users, ({ one, many }) => ({
data: one(data, { fields: [users.userID], references: [data.userID] }),
}));

export const data = pgTable("data", {
userID: integer("user_id").primaryKey().references(() => users.userID),
// some other data here
});
it gives me a type error on both tables:
'data' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(
'data' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(
Any idea why this might be? Thanks for the help!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server