import { relations } from "drizzle-orm";
import { pgTable, primaryKey, varchar } from "drizzle-orm/pg-core";
import { posts } from "./posts";
import { users } from "./users";
export const usersToPosts = pgTable(
"users_to_posts",
{
userId: varchar("user_id")
.notNull()
.references(() => users.id),
postId: varchar("post_id")
.notNull()
.references(() => posts.id),
},
(t) => ({
pk: primaryKey(t.userId, t.postId),
})
);
export const usersToPostsRelations = relations(usersToPosts, ({ one }) => ({
post: one(posts, {
fields: [usersToPosts.postId],
references: [posts.id],
}),
user: one(users, {
fields: [usersToPosts.userId],
references: [users.id],
}),
}));
import { relations } from "drizzle-orm";
import { pgTable, primaryKey, varchar } from "drizzle-orm/pg-core";
import { posts } from "./posts";
import { users } from "./users";
export const usersToPosts = pgTable(
"users_to_posts",
{
userId: varchar("user_id")
.notNull()
.references(() => users.id),
postId: varchar("post_id")
.notNull()
.references(() => posts.id),
},
(t) => ({
pk: primaryKey(t.userId, t.postId),
})
);
export const usersToPostsRelations = relations(usersToPosts, ({ one }) => ({
post: one(posts, {
fields: [usersToPosts.postId],
references: [posts.id],
}),
user: one(users, {
fields: [usersToPosts.userId],
references: [users.id],
}),
}));