Last active
October 26, 2017 13:27
-
-
Save bhudgeons/7138582 to your computer and use it in GitHub Desktop.
Slick notIn example
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
// This is the query to find all of a user's | |
// non-academy courses. In other words... | |
// I want to list all of this user's courses, | |
// but exclude courses associated with | |
// academies in which this user is a member. | |
val user:User = ... | |
val excludeTheseAcademies = (for { | |
au <- AcadUser if au.userId === user.id | |
} yield au).map(_.acadId) | |
val courseQuery = for { | |
cu <- CourseUser if cu.userId === user.id | |
course <- Courses if course.id === cu.courseId | |
if course.acadId notIn excludeTheseAcademies | |
} yield course | |
// NOTE: Slick 2.1.0 removed notIn ... now you'd just do it like this: | |
val user:User = ... | |
val excludeTheseAcademies = (for { | |
au <- AcadUser if au.userId === user.id | |
} yield au).map(_.acadId) | |
val courseQuery = for { | |
cu <- CourseUser if cu.userId === user.id | |
course <- Courses if course.id === cu.courseId | |
if !(course.acadId in excludeTheseAcademies) | |
} yield course |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment