Permalink
Browse files

added mapped projection and query that uses it but can't get it to work

  • Loading branch information...
1 parent 1fc97d5 commit eb4c63b4dca2b04898da53b61bb15147c478ff1c @burma-shave committed Apr 15, 2013
Showing with 11 additions and 0 deletions.
  1. +11 −0 src/main/scala/com/typesafe/slick/examples/lifted/MultiDBCakeExample.scala
View
11 src/main/scala/com/typesafe/slick/examples/lifted/MultiDBCakeExample.scala
@@ -31,6 +31,8 @@ trait PictureComponent { this: Profile => //requires a Profile to be mixed in...
case class User(name: String, picture: Picture, id: Option[Int] = None)
+case class UserAndPicId(name: String, picId: Int)
+
trait UserComponent { this: Profile with PictureComponent => //requires Profile and Picture (see def insert)
import profile.simple._
@@ -39,6 +41,7 @@ trait UserComponent { this: Profile with PictureComponent => //requires Profile
def name = column[String]("USER_NAME", O.NotNull)
def pictureId = column[Int]("PIC_ID", O.NotNull)
def * = name ~ pictureId ~ id
+ def justNameAndPicId = name ~ pictureId <> (UserAndPicId, UserAndPicId.unapply _)
private def autoInc(implicit session: Session) = name ~ pictureId returning id into {
case (_, id) => id
@@ -52,6 +55,11 @@ trait UserComponent { this: Profile with PictureComponent => //requires Profile
val id = autoInc.insert(user.name, picture.id.get)
user.copy(picture = picture, id = id)
}
+
+ def userAndPicById = for {
+ id <- Parameters[Int]
+ user <- this if user.id === id
+ } yield justNameAndPicId
}
}
@@ -93,6 +101,9 @@ object MultiDBCakeExample {
println(" Inserted user: " + Users.insert(user3))
println(" All pictures: " + Query(Pictures).list)
println(" All users : " + Query(Users).list)
+
+ println(" Attempting to fetch UserAndPicId by id")
+ Users.userAndPicById(1).firstOption
}
}

0 comments on commit eb4c63b

Please sign in to comment.