I would like to left-join two tables and then map it into the following object where the metadata object should be null if no metadata was joined:
data class ObjectDto(
val objectId: String,
val name: String,
val metadata: MetadataDto?
)
data class MetadataDto(
val description: String,
val comment: String
)
I tried to follow the docs about nested objects but was not able to map it correctly with the following code:
suspend fun getArrangements(objectIds: List<String>): List<ObjectDto> {
return Flux.from(
jooqDsl
.select(
OBJECT.OBJECT_ID,
OBJECT.NAME,
row(
METADATA.DESCRIPTION,
METADATA.COMMENT,
).mapping(::MetadataDto).`as`("METADATA")
)
.from(
OBJECT.leftJoin(METADATA)
.on(OBJECT.OBJECT_ID.eq(METADATA.OBJECT_ID))
)
.where(OBJECT.OBJECT_ID.`in`(objectIds))
)
.map {
it.into(ObjectDto::class.java)
}
.collectList()
.awaitSingle()
}
The executed query is returning the correct data however the metadata is not mapped and always null. What am I doing wrong?