Created
March 28, 2013 19:57
-
-
Save snichme/5266306 to your computer and use it in GitHub Desktop.
Is this a good way for producing a json respons of users with their cars?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val carWriter = Json.writes[Car] | |
implicit val userWithCarWriter = Json.writes[UserWithCar] | |
def users = Action { | |
val users = DB.withSession { implicit session => | |
val q = for { | |
u <- Users | |
c <- Cars if u.carId === c.id | |
} yield (u, c) | |
q.list.map { row => | |
UserWithCar(row._1.id, row._1.email, row._1.name, Car(row._2.id, row._2.name)) | |
} | |
} | |
Ok(Json.toJson(users)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment