DT
Join ServerDrizzle Team
help
Relations, three level nested where?
Given a
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?
Currently it doesn't seem to work, although of course in this example I can start with Role instead to achieve the same thing....
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....
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