© 2026 Hedgehog Software, LLC

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

having trouble to include relations with query function

how do you exactly use the
with
with
field in the query options to include relations ?, my functions always returned
referencedTable
referencedTable
error

my relation is declared like the following
export const eventsRelations = relations(events, ({ many, one }) => ({
  host: one(users, {
    fields: [events.createdBy],
    references: [users.id],
  }),
}));

export const usersRelations = relations(users, ({ many }) => ({
  events: many(events),
}));
export const eventsRelations = relations(events, ({ many, one }) => ({
  host: one(users, {
    fields: [events.createdBy],
    references: [users.id],
  }),
}));

export const usersRelations = relations(users, ({ many }) => ({
  events: many(events),
}));



and here's the query

  async getEventBySlug(slug: string): Promise<selectEvent | undefined> {
    const data = await db.query.events.findFirst({
      with: { host: true },
      where: and(eq(events.slug, slug), isNull(events.deletedAt)),
    });

    if (data) return data as selectEvent;
    else return undefined;
  }
  async getEventBySlug(slug: string): Promise<selectEvent | undefined> {
    const data = await db.query.events.findFirst({
      with: { host: true },
      where: and(eq(events.slug, slug), isNull(events.deletedAt)),
    });

    if (data) return data as selectEvent;
    else return undefined;
  }


i've also tried to change the
with
with
object to
{users:true}
{users:true}
but still receiving the
referencedTable
referencedTable
error
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

Relations include query
Drizzle TeamDTDrizzle Team / help
3y ago
Include count of relations
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle-zod Include Relations
Drizzle TeamDTDrizzle Team / help
3y ago
Having trouble understanding type on query with relation
Drizzle TeamDTDrizzle Team / help
3y ago