Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2013 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5286257 to your computer and use it in GitHub Desktop.
Save anonymous/5286257 to your computer and use it in GitHub Desktop.
// projects for which the given user has a matching skill but is not a member.
// select x2."id", x2."name", x2."created", x3."id", x3."username"
// from "projects" x2, "users" x3
// where ((not (x2."id" in (select x4."project_id" from "project_members" x4 where x4."user_id" = 834)))
// and (x2."id" in (
// select x5.x6 from (
// select x7."project_id" as x6, x7."skill_id" as x8 from "project_skills" x7) x5
// inner join (select x9."user_id" as x10, x9."skill_id" as x11 from "skillsets" x9) x12
// on (x5.x8 = x12.x11) and (x12.x10 = 834))))
// and (x3."id" = x2."owner")
def listEligibleProjects(userId: Int)(implicit session: Session): Seq[ProjectInfo] =
{
val q = for {
p <- Projects if (! (p.id in {
for (pm <- ProjectMembers if pm.userId === userId) yield pm.projectId
}) && (p.id in {
// for ((ps, us) <- ProjectSkills innerJoin UserSkills on
// ((ps, us) => ps.skillId === us.skillId && us.userId === userId)) yield ps.projectId
for {
ps <- ProjectSkills
us <- UserSkills if us.skillId === ps.skillId && us.userId === userId
} yield ps.projectId
}))
o <- p.owner
} yield p.id ~ p.name ~ p.created ~ o.id ~ o.username
logSQL(q.selectStatement)
listProjects(q.run.distinct)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment