What is wrong with my one to many schema?
export const jobs = pgTable('jobs', {
id: serial('id').primaryKey(),
user_id: varchar('user_id', { length: 15 })
.notNull()
.references(() => user.id),
title: varchar('title').notNull(),
description: varchar('description').notNull(),
company: varchar('company').notNull(),
role: varchar('role').notNull()
});
export const jobsRelations = relations(jobs, ({ many }) => ({
badges: many(badges)
}));
export const badges = pgTable('badges', {
id: serial('id').primaryKey(),
label: varchar('label').notNull(),
color: text('text', { enum: ['blue', 'orange', 'red', 'green', 'pink', 'purple'] }),
jobId: integer('job_id')
});
export const badgesRelations = relations(jobs, ({ one }) => ({
test: one(jobs, {
fields: [badges.jobId],
references: [jobs.id]
})
}));
export const jobs = pgTable('jobs', {
id: serial('id').primaryKey(),
user_id: varchar('user_id', { length: 15 })
.notNull()
.references(() => user.id),
title: varchar('title').notNull(),
description: varchar('description').notNull(),
company: varchar('company').notNull(),
role: varchar('role').notNull()
});
export const jobsRelations = relations(jobs, ({ many }) => ({
badges: many(badges)
}));
export const badges = pgTable('badges', {
id: serial('id').primaryKey(),
label: varchar('label').notNull(),
color: text('text', { enum: ['blue', 'orange', 'red', 'green', 'pink', 'purple'] }),
jobId: integer('job_id')
});
export const badgesRelations = relations(jobs, ({ one }) => ({
test: one(jobs, {
fields: [badges.jobId],
references: [jobs.id]
})
}));
Types of property 'tableName' are incompatible.
Type '"badges"' is not assignable to type '"jobs"'.
Types of property 'tableName' are incompatible.
Type '"badges"' is not assignable to type '"jobs"'.
![No description](https://cdn.answeroverflow.com/1142519233637527572/image.png)
2 Replies
Is it still unresolved?
Hey, I goofed here and did the same thing you have the values for field and reference swapped.