Drizzle TeamDT
Drizzle Team3y ago
2 replies
tapoah_adama

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]
    })
}));


I get the error:
Types of property 'tableName' are incompatible.
          Type '"badges"' is not assignable to type '"jobs"'.
image.png
Was this page helpful?