© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
4 replies
cobite

How to add to the database where the table has a many relationship to another table

I have a users table, which has a many relationship to to a posts table.

I want to add a new user to the table, which I can do, but how do I go about adding new posts to that user? Does it add a full post object to the user? Or just an id to the new post which will be in the post table?

export const users = pgTable('users', {
  id: uuid('id').primaryKey().defaultRandom().unique().notNull(),
  username: varchar('username', { length: 512 }).unique().notNull(),
});

export const usersRelations = relations(users, ({ many }) => ({
  posts: many(posts),
}));
export const users = pgTable('users', {
  id: uuid('id').primaryKey().defaultRandom().unique().notNull(),
  username: varchar('username', { length: 512 }).unique().notNull(),
});

export const usersRelations = relations(users, ({ many }) => ({
  posts: many(posts),
}));
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

SQLite 'WHERE table.relationship (one to many) > 0'
Drizzle TeamDTDrizzle Team / help
2y ago
Many-to-Many where in far table
Drizzle TeamDTDrizzle Team / help
3y ago
How to query from a many to many relationship?
Drizzle TeamDTDrizzle Team / help
3y ago
Unable to query a table with another many to many relation
Drizzle TeamDTDrizzle Team / help
2y ago