tincho
tincho
DTDrizzle Team
Created by tincho on 4/13/2024 in #help
Group related items in relation query
If annyone have a similar problem i solved this way: const proffesionals = db .select({ id: proffesionalTable.id, firstName: proffesionalTable.firstName, lastName: proffesionalTable.lastName, availability: proffesionalTable.availability, serviceId: proffesionalServiceTable.serviceId }) .from(proffesionalTable) .where(eq(proffesionalTable.userId, userId)) .leftJoin( proffesionalServiceTable, eq(proffesionalServiceTable.proffesionalId, proffesionalTable.id) ) .as('proffesionals'); const sq = await db .select({ id: proffesionals.id, firstName: proffesionals.firstName, lastName: proffesionals.lastName, availability: proffesionals.availability, servicesIds: sql<number[]>json_group_array(${proffesionals.serviceId}) }) .from(proffesionals) .groupBy(proffesionals.id);
4 replies