Can't infer relationship one-to-one

I'm trying to follow the relationship docs to set a relationship between a user and a role, but I'm getting the error Error: There is not enough information to infer relation "users.role" although I'm sure I'm following the example on this page: https://orm.drizzle.team/docs/rqb#one-to-one

Can anyone help me find the issue?

Code:
export const users = pgTable(
  "users",
  {
    id: serial("id").primaryKey(),
    email: varchar("email", { length: 150 }).unique().notNull(),
  },
  (table) => {
    return {
      tokenIdx: index("email_idx").on(table.email),
    };
  }
);

export const usersRelations = relations(users, ({ one }) => ({
  role: one(roles),
}));

export const roles = pgTable("roles", {
  id: serial("id").primaryKey(),
  userId: integer("user_id")
    .references(() => users.id, {
      onDelete: "cascade",
    })
    .notNull(),
  staffRole: rolesEnum("role").notNull(),
});

export const db = drizzle(queryClient, {
  schema: {
    users,
    usersRelations,
    roles,
  },
});
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Was this page helpful?