Skip to content

Commit

Permalink
Add failing test for #175
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Jan 14, 2014
1 parent cf5329b commit abe9197
Showing 1 changed file with 34 additions and 0 deletions.
Expand Up @@ -28,4 +28,38 @@ class CountTest extends TestkitTest[RelationalTestDB] {
val q4 = testTable.take(2).length
assertEquals(2, q4.run)
}

def testJoin {
class Categories(tag: Tag) extends Table[(Int, String)](tag, "cat_j") {
def id = column[Int]("id")
def name = column[String]("name")
def * = (id, name)
}
val categories = TableQuery[Categories]

class Posts(tag: Tag) extends Table[(Int, String, Int)](tag, "posts_j") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def title = column[String]("title")
def category = column[Int]("category")
def * = (id, title, category)
}
val posts = TableQuery[Posts]

(categories.ddl ++ posts.ddl).create
categories ++= Seq((1, "Scala"), (2, "JVM"), (3, "Java"), (4, "Erlang"), (5, "Haskell"))
posts ++= Seq((1, "Shiny features", 1), (2, "HotSpot", 2))

val joinedQuery = for {
c <- categories
p <- posts
if p.category === c.id
} yield (c, p)

val q1 = joinedQuery.length
assertEquals(2, q1.run)

val q2 = Query(joinedQuery.length)
assertEquals(Vector(2), q2.run)

}
}

0 comments on commit abe9197

Please sign in to comment.