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]
})
}));
I get the error:
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
2 Replies
Andrii Sherman
Andrii Sherman17mo ago
Is it still unresolved?
ag1155
ag115515mo ago
Hey, I goofed here and did the same thing you have the values for field and reference swapped.
Want results from more Discord servers?
Add your server