How to fetch into multiple classes?

34 Views Asked by At

Let's say I have 3 tables that are related. How can I query all 3 inner joined and get the result in 3 different record types for each table?

e.g. something like:

dslContext
.select(A.fields()).from(B).innerJoin(A).on(...)
.fetchInto(A,B) ???
1

There are 1 best solutions below

0
Lukas Eder On

Assuming you want something like Record3<ARecord, BRecord, CRecord>, you can simply nest the projeced records:

Result<Record3<ARecord, BRecord, CRecord>> result =
ctx.select(A, B, C) // Project the tables directly, not their fields
   .from(A)
   .join(B).on(...)
   .join(C).on(...)
   .fetch();