Drizzle TeamDT
Drizzle Team3y ago
78 replies
Piotrek

Nested joins / where on relation

Hey guys! I have a question regarding filtering a query. Basically, I need to filter the query by
order
relation -
order.date
is the field I want to filter by. However, I've noticed that filtering by relations is not yet supported. How do I write the query with joins? I can't figure out how to created nested joins (
subOrders -> order
and
subOrders -> product -> kitchens -> kitchen
etc.)

This is my query:
const suborders = await db.query.subOrders.findMany({
    where: and(isNull(subOrders.kitchenId)),
    columns: {
      id: true,
      quantity: true,
    },
    with: {
      order: true,
      product: {
        columns: {
          id: true,
          performancePoints: true,
          prepTime: true,
        },
        with: {
          kitchens: {
            with: {
              kitchen: {
                columns: {
                  id: true,
                  performancePoints: true,
                },
              },
            },
          },
          kitchenDependentProperties: {
            columns: {
              kitchenId: true,
              productionPrice: true,
              purchasePrice: true,
            },
          },
        },
      },
    },
  });
Was this page helpful?