Creating One-to-Many relations
Question regarding creating relations. I have created a usersTable that has an id, I am currently trying to create a suggestionsTable and add relations to the usersTable in the suggestionsTable: I have the following but I am getting an error on the fields property that says that it doesn’t exist.
Picture for reference:
import { pgTable, text, integer, timestamp } from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";
import { usersTable } from "./user";
export const suggestionsTable = pgTable("suggestions", {
id: integer("id").primaryKey().notNull(),
userId: integer("user_id").notNull(),
content: text("content").notNull(),
timestamp: timestamp("timestamp").notNull(),
});
export const usersRelations = relations(usersTable, ({ one, many }) => ({
suggestions: many(suggestionsTable, {
fields: [suggestionsTable.userId],
references: [usersTable.id],
}),
}));Picture for reference:
