not getting proper type inference on any queries

i'm trying to get jobs with companies using drizzle queries
const job = await db.query.jobs.findFirst({
where: eq(jobs.id, id),
with: {
company: true,
},
});

const title = `${job.title} at ${job.company.name}`;
const job = await db.query.jobs.findFirst({
where: eq(jobs.id, id),
with: {
company: true,
},
});

const title = `${job.title} at ${job.company.name}`;
but for some reason the type of jobs does not have the company property: Property 'company' does not exist on type '...' i have made sure to define the relation in my schema file
export const jobs = pgTable("jobs", {
id: uuid("id").notNull().primaryKey().defaultRandom(),
companyId: uuid("company_id")
.references(() => companies.id, { onDelete: "cascade" })
.notNull(),
/* ... */
});

export const jobCompanyRelation = relations(jobs, ({ one }) => ({
company: one(companies, {
fields: [jobs.companyId],
references: [companies.id],
}),
}));
export const jobs = pgTable("jobs", {
id: uuid("id").notNull().primaryKey().defaultRandom(),
companyId: uuid("company_id")
.references(() => companies.id, { onDelete: "cascade" })
.notNull(),
/* ... */
});

export const jobCompanyRelation = relations(jobs, ({ one }) => ({
company: one(companies, {
fields: [jobs.companyId],
references: [companies.id],
}),
}));
using drizzle-orm 0.29.3
1 Reply
sten
sten11mo ago
Hey I got the same issue, did you resolve this?
Want results from more Discord servers?
Add your server