Yehuda Krupka
Yehuda Krupka
DTDrizzle Team
Created by Yehuda Krupka on 10/26/2023 in #help
Select with a join that returns eagerly loaded submodels
hey all, is it possible to do a select on a model using a join and return the model with eagerly loaded fk models. Something like this where I'm joing wharehouse to location to filter on location.city but i want the location to be returned nested in wharehouse not alongside getWarehousesInCity: publicProcedure .input(z.string()) .query(async ({ctx, input}) => { return await ctx.db.select({ warehouses, with:{ locations: true } }).from(warehouses).innerJoin(locations, eq(warehouses.location_id, locations.location_id)).where(eq(locations.city_id, input)).execute(); }),
1 replies