playframework/Play20 — comment on commit f35fd305d98038ab0fe3f8076368ee7f8d90015b
File:  line 0
By sadache:

(User.instance ~ Permission.instance
*).map(_.groupBy(_._1).toSeq.headOption.map {
case (u, ps) => u.copy(permissions = ps.map(_._2).toSet)
})

On Fri, Jan 6, 2012 at 5:07 PM, recalcitrant <
reply@reply.github.com
> wrote:

> Very nice, almost there, now I am wondering how to get the User out of the
>
> anorm.ResultSetParser[Seq[models.auth.User]]
>
> so I can get the user as a singleOpt:
>
> val user = User.byId(42).getOrElse(...)
>
> def byId(id: Long): Option[User] = DB.withConnection(implicit connection =>
> SQL(sql + "and ua.id = {id}" + order).on("id" ->
> id).as(User.withPermissions.singleOpt))
>
> val withPermissions = (User.instance ~ Permission.instance
> *).map(_.groupBy(_._1).toSeq.map {
> case (u, ps) => u.copy(permissions = ps.map(_._2).toSet)
> })
>
> Thank you again for you time.
>
> ---
> Reply to this email directly or view it on GitHub:
>
> https://github.com/playframework/Play20/commit/f35fd305d98038ab0fe3f8076368ee7f8d90015b#commitcomment-844047
>

--
www.sadekdrobi.com
ʎdoɹʇuǝ