https://kotlinlang.org logo
#exposed
Title
# exposed
s

Sergio Casero

11/14/2018, 4:16 PM
Hello guys! Just small and noob question, how can I retrieve the "sum" value in the result row when using groupBy?
For example like this:
Copy code
ProductVo.slice(ProductVo.reference,ProductVo.quantity.sum())
                .selectAll()
                .groupBy(Prouct.reference)
I can retrieve productVo.reference with:
Copy code
map { it[ProductVo.reference] }
But no the "quantity sum" value, I've tested with alias but didn't work
I can get the value by using
data[1]
but... it's a workaround
o

orangy

11/14/2018, 6:39 PM
groupBy
is a map from key to list of values, you might want
associateBy
s

Sergio Casero

11/14/2018, 6:53 PM
Will take a look
t

tapac

11/14/2018, 8:28 PM
Copy code
val qSum = ProductVo.quantity.sum()
ProductVo.slice(ProductVo.reference, qSum)
                .selectAll()
                .groupBy(ProductVo.reference)
               .map{ it[qSum] }
🔝 1
s

Sergio Casero

11/14/2018, 8:44 PM
ahhhhh, thanks! I'm stupid haha