having trouble to include relations with query function

how do you exactly use the with field in the query options to include relations ?, my functions always returned 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),
}));



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;
  }


i've also tried to change the with object to {users:true} but still receiving the referencedTable error
Was this page helpful?