Skip to content

Instantly share code, notes, and snippets.

@snichme
Created March 28, 2013 19:57
Show Gist options
  • Save snichme/5266306 to your computer and use it in GitHub Desktop.
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?
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