TS Types when using schema and "with"

So I've recently started a project and after using Prisma for an OSS i've been contributing to I decided to try out Drizzle. Overall really liking it, but I'm running into a weird thing where sometimes relationships will show up when added in with the with property, but other times they refuse to.

For example, in this case there is a many to many relationship between users and households; a single user can belong to many households, and households can have many users. The DB schema is user <-> users_to_households(user.id, household.id) <-> household

const tmpUser = await db.query.users.findFirst({
    with: {
      households: {
        with: true,
      },
    },
    where({ id }, { eq }) {
      return eq(id, user.id);
    }
  });


Where users has the following schema

export const users = authSchema.table('users', {
  id: uuid('id').notNull().primaryKey(),
  email: varchar('email').notNull(),
});

export const usersToHouseholds = pgTable(
  'users_to_households',
  {
    id: uuid('id').notNull().primaryKey().defaultRandom(),
    userId: uuid('user_id').notNull(),
    householdId: text('household_id').notNull().references(() => households.id, { onDelete: 'cascade' }),
  },
);

export const usersToHouseholdsRelations = relations(usersToHouseholds, ({ one }) => ({
  user: one(users, {
    fields: [usersToHouseholds.userId],
    references: [users.id],
  }),
  household: one(households, {
    fields: [usersToHouseholds.householdId],
    references: [households.id],
  })
}));

export const usersHouseholds = relations(users, ({ many }) => ({
  households: many(usersToHouseholds)
}));

export const householdUsers = relations(households, ({ many }) => ({
  users: many(usersToHouseholds)
}));

export const households = pgTable(
  'households',
  {
    id: text('id').primaryKey().$defaultFn(() => ulid()),
    name: text('name').notNull(),
    createdAt: date('created_at').notNull().defaultNow()
  },
  // Creating an index on the name as we will search on it.
  ({ name }) => ({
    name: index('name_index').on(name)
  })
);


Gives me the attached image, but other relationships work without error.

I feel like I should also note that up until a few days ago, the types here were working just fine.
image.png
Was this page helpful?