Added more join examples
This commit is contained in:
parent
a960f43cb6
commit
325f03a2c7
@ -95,11 +95,27 @@ class SlickLibraryDbio extends Tables {
|
|||||||
author <- Authors filter (_.id === authorId)
|
author <- Authors filter (_.id === authorId)
|
||||||
} yield (author, book)
|
} yield (author, book)
|
||||||
|
|
||||||
// lazy val authorOfBook3 = (bookId: Long) =>
|
lazy val authorOfBook3 = (bookId: Long) =>
|
||||||
// for {
|
for {
|
||||||
// authorId <- bookById(bookId).map(_.map(_.authorId))
|
(author, book) <- Authors join
|
||||||
// (authors) <- Authors filter (_.id === authorId)
|
Books on (_.id === _.authorId) filter {
|
||||||
// } yield (authors)
|
case (authors, books) => books.id === bookId
|
||||||
|
} map {
|
||||||
|
case (authors, books) =>
|
||||||
|
(authors.id, authors.name).mapTo[Author] -> (
|
||||||
|
books.title,
|
||||||
|
books.authorId,
|
||||||
|
books.createdAt
|
||||||
|
).mapTo[BookDTO]
|
||||||
|
}
|
||||||
|
} yield (author, book)
|
||||||
|
|
||||||
|
lazy val authorOfBook4 = (bookId: Long) =>
|
||||||
|
for {
|
||||||
|
book <- Books
|
||||||
|
author <- book.authorsFk
|
||||||
|
} yield (author, book)
|
||||||
|
|
||||||
}
|
}
|
||||||
case class BookWithoutId(title: String, authorId: Long)
|
case class BookWithoutId(title: String, authorId: Long)
|
||||||
// def test() = {
|
// def test() = {
|
||||||
|
Loading…
Reference in New Issue
Block a user