rcamf
rcamf
DTDrizzle Team
Created by rcamf on 2/15/2024 in #help
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.
4 replies