Using "which" to check an alias isn't working.

      // missing FROM-clause entry for table "notSubcategory"
      search?.categoryId ? eq(notSubcategoryTable.categoryId, search.categoryId) : undefined,
      // works fine
      search?.subcategoryId
        ? eq(productTable.categoryId, search.subcategoryId)
        : undefined,

      ...(select?.category
        ? {
            subcategory: categoryTable,
            category: notSubcategoryTable,
          }
        : {}),

    if (select?.category) {
      query.leftJoin(
        categoryTable,
        eq(productTable.categoryId, categoryTable.id)
      );
      query.leftJoin(
        notSubcategoryTable,
        eq(notSubcategoryTable.id, categoryTable.categoryId)
      );

      groupBy.push(notSubcategoryTable.id);
      groupBy.push(categoryTable.id);
    }

Am I missing something?
Was this page helpful?