How to filter by joined tables with Drizzle query syntax?

Hi there! I was wondering if there was a way to query by a joined table using drizzle query syntax. Here's a concise example:

TABLE users
id
name

TABLE info
id
user_id
organization_id
description

users.id <-> info.user_id (one-to-one)


import { posts } from './schema';

const results = await db.users.findMany({
  with: {
    info: true;
  },
  where: (users, { eq }) => {
    return [eq(info.organizationId, '0')];
  }
});

console.log(results);

// error: PostgresError: column users.organization_id does not exist


So how is this supposed to be done? users <-> info is 1 to 1 so with .select() query I would just filter by the joined table like I'm trying above, but this is not working in this case. I can't add a where to the info block since it's a one to one.
Was this page helpful?