Last active
May 25, 2016 15:22
-
-
Save mobiworx/e2472d87a87d3b2622e7 to your computer and use it in GitHub Desktop.
slick - query composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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