Given a scala list such as:
List( ~(OuterObj,InnerObj1), ~(OuterObj, InnerObj2), ...)
Where all the OuterObj's are the same and the InnerObj's can be different, I need to "group" this into a single OuterObj object that contains a list of the InnerObj's.
In other words, OuterObj
has an attribute innerList
that is empty, but I need to transform the original list into a single OuterObj such that:
OuterObj.innerList = List(InnerObj1, InnerObj2, ....)
I tried using .groupBy(_._1)
but this didn't group the objects properly and I wasn't sure where to go from there.
In case context helps, the original List is a result of an Anorm join query with a one-to-many (1 outerObj to many innerObj) using the following parser pattern:
SQL(" joining outer on inner sql using a left join.. ").as(OuterObj.parse ~ InnerObj.parse *) // this is what creates the list of tuples