One-to-One Relation in Drizzle ORM

From the Drizzle ORM cheat sheet · Relations · verified Jul 2026

One-to-One Relation

Define a one-to-one relationship between users and profiles.

typescript
import { relations } from 'drizzle-orm';
import { pgTable, serial, text,
  integer } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
});

export const profiles = pgTable('profiles', {
  id: serial('id').primaryKey(),
  bio: text('bio'),
  avatarUrl: text('avatar_url'),
  userId: integer('user_id').unique().notNull(),
});

export const usersRelations = relations(users, ({ one }) => ({
  profile: one(profiles),
}));

export const profilesRelations = relations(profiles, ({ one }) => ({
  user: one(users, {
    fields: [profiles.userId],
    references: [users.id],
  }),
}));
💡 one() on both sides makes it one-to-one
⚡ Add .unique() on FK column to enforce in DB
📌 fields/references go on the FK-owning side only
🟢 The non-FK side just uses one(table)
relationsone-to-one

More Drizzle ORM tasks

Back to the full Drizzle ORM cheat sheet