Type of relations when using with is not correctly set

I have two schemas:
export const jobs = pgTable('job', {
...primaryId,
});

export const setups = pgTable('setup', {
...primaryId,
jobId: uuid('job_id')
.notNull()
.references(() => jobs.id, {
onDelete: 'cascade',
}),
});
export const jobs = pgTable('job', {
...primaryId,
});

export const setups = pgTable('setup', {
...primaryId,
jobId: uuid('job_id')
.notNull()
.references(() => jobs.id, {
onDelete: 'cascade',
}),
});
They are in a one-to-one relation with the relations defined:
export const jobRelations = relations(jobs, ({ one }) => ({
setup: one(setups),
}));

export const setupRelations = relations(setups, ({ one }) => ({
job: one(jobs, {
fields: [setups.jobId],
references: [jobs.id],
}),
}));
export const jobRelations = relations(jobs, ({ one }) => ({
setup: one(setups),
}));

export const setupRelations = relations(setups, ({ one }) => ({
job: one(jobs, {
fields: [setups.jobId],
references: [jobs.id],
}),
}));
However when I run following query the setup property on a job is not properly typed:
const data = await db.query.jobs.findFirst({
with: {
setup: true
}
});
const data = await db.query.jobs.findFirst({
with: {
setup: true
}
});
Instead it has following type:
(property) setup: {
[x: string]: any;
} | {
[x: string]: any;
}[] | null | undefined
(property) setup: {
[x: string]: any;
} | {
[x: string]: any;
}[] | null | undefined
I tried following the other posts to solve this in the discord and also created the IncludeRelations type that was suggested in other similar posts, but nothing seems to be working for me.
2 Replies
Mykhailo
Mykhailo10mo ago
Hello, @rcamf! Is it possible to provide reproduction repo? I am using drizzle-orm: ^0.29.3 and couldn't reproduce it
No description
rcamf
rcamfOP10mo ago
Sadly I cannot provide a reproduction repo, but I am using drizzle-orm: beta right now. Could it possibly be related to that. Okay I think I have figured out the cause of the problem. Somehow my relations are not properly added to the schema. Since setting it up like you did works for me as well. Thanks a lot
Want results from more Discord servers?
Add your server