Skip to content

Instantly share code, notes, and snippets.

@bhudgeons
Last active October 26, 2017 13:27
Show Gist options
  • Save bhudgeons/7138582 to your computer and use it in GitHub Desktop.
Save bhudgeons/7138582 to your computer and use it in GitHub Desktop.
Slick notIn example
// 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