© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
3 replies
rcamf

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
IncludeRelations
type that was suggested in other similar posts, but nothing seems to be working for me.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Duplicate relations when using `with`
Drizzle TeamDTDrizzle Team / help
3y ago
Cascade onDelete when not using FK relations
Drizzle TeamDTDrizzle Team / help
3y ago
Relations not building into type
Drizzle TeamDTDrizzle Team / help
3y ago
Type for select with relations?
Drizzle TeamDTDrizzle Team / help
3y ago