Skip to content

Instantly share code, notes, and snippets.

@mobiworx
Last active May 25, 2016 15:22
Show Gist options
  • Save mobiworx/e2472d87a87d3b2622e7 to your computer and use it in GitHub Desktop.
Save mobiworx/e2472d87a87d3b2622e7 to your computer and use it in GitHub Desktop.
slick - query composition
// your "subquery"
val q1 = (for {
(a, b) <- someTable
.leftJoin(anotherTable).on(_.id === _.other_id)
} yield (a.id, b.id)).groupBy(_._1).map {
case (id, group) => (id, group.map(_._2.asColumnOf[String]))
}
val q2 = for {
((a, b), c) <- aaaTable
.leftJoin(bbbTable).on(_.id === _.other_id)
.leftJoin(q1).on(_._1 === _._1) // refers back to q1
} yield (a, b, c)
val result = q2.list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment