Relations, three level nested where?

Ttacomanator5/26/2023
Given a User, Role, RoleToUser many-to-many relation:

export const userRelations = relations(User, ({ many }) => ({
  roleToUser: many(RoleToUser),
}));

export const roleRelations = relations(Role, ({ many }) => ({
  roleToUser: many(RoleToUser),
}));

export const roleToUserRelations = relations(RoleToUser, ({ one }) => ({
  role: one(Role, { fields: [RoleToUser.roleId], references: [Role.id] }),
  user: one(User, { fields: [RoleToUser.userId], references: [User.id] }),
}));


Are we able to filter with where on the third level to, for example, find all users belonging to a role of the given name?

db.query.User.findMany({
  with: {
    roleToUser: {
      with: {
        role: {
          where: eq(Role.name, "現場監督"),
        },
      },
    },
  },
}),


Currently it doesn't seem to work, although of course in this example I can start with Role instead to achieve the same thing....
Bbloberenober6/2/2023
Currently, you can filter the tables on their own fields only. Filtering on deeply nested fields is not implemented - https://github.com/drizzle-team/drizzle-orm/issues/696