2

I'm trying to do a left join with Slick.

I have two case classes (Book and Author) and 2 tables

If I do this :

(for {
       (book, author) <- Books leftJoin Authors on (_.authorId === _.id)
     } yield (book, author.?)
).list

The result is a List[Book, Option[Authors.type]] and I need a List[Book, Option[Author]]

Do you know why I get the wrong type with my query?

Note : my Authors object links well with the Author case class:

object Authors extends Table[Author]("author"){...}

Thanks :)

Loïc

4

1 回答 1

0

我有一个解决方法,但我不知道这是否是正确的解决方案。

我检索作者可选列,然后在结果中使用 map 函数来创建 (Book, Author) 元组对象。

val query = for {
(book, author) <- Books leftJoin Companies on (_.authorId === _.id)
} yield (book, author.id.?, author.name.?)

val result = query.list.map(row => (row._1, row._2.map(value => Author(Option(value), row._3.get))))
于 2013-03-08T07:40:09.777 回答