I want to fetch a DTO as follows:
data class CartItemDto(
val id: UUID
val product: ProductDTO
)
The only way I can currently achieve is is by doing two separate queries and then combining those two results into the data class above, but I want to do everything in one jOOQ query. Multiset is not an option and whenever we use jsonObject in a custom field, it won't work.
The only examples I can find on the internet are for DTO's with lists:
data class CartItemDto(
val id: UUID
val product: List<ProductDto>
)
Extra information
ProductDto:
data class ProductDto(
val id: UUID
val title: String
)
Current query:
databaseRepository.getConnection()
.select(CART_ITEM.CART_ID,
row(
PRODUCT.ID,
).mapping(::ProductDto))
.from(CART_ITEM)
.join(PRODUCT)
.on(PRODUCT.ID.eq(CART_ITEM.PRODUCT_ID))
.fetch(Records.mapping(::CartItemDto))
But this will only work if I make the data class fields nullable.