> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>
Nailed it! There haven't really been any more updates on this thread, but it seems to still be relevant. Because of that, and because there isn't an answer, I thought I'd throw mine in for consideration.
Anorm doesn't support 'IN' clauses. I doubt they ever will. There's nothing you can do to make them work, I even read a post where anorm specifically took out those clauses because they made Anorm feel 'like an ORM'.
It's fairly easy, however, to wrap the SqlQuery in a short class that supports the IN clause, and then convert that class into a SqlQuery when needed.
Instead of pasting the code in here, because it gets a little long, here is the link to my blog, where I've posted the code and how to use it.
Basically, when you have the code from my blog, your statements look like this:
RichSQL(""" SELECT * FROM users WHERE id IN ({userIds}) """).onList("userIds" -> userIds).toSQL.as(userParser *)(connection)
val userIds = List(1, 3, 5)
SQLin"select * from users where id in ($userIds)".as(userParser *)
def findAllWithRole(roles: List[String]) = DB.withConnection { implicit c =>
val s = roles.map(x => s"'$x'").mkString(", ")
SQL(
s"""
|select distinct u.* from "user" u
| join user_role ur on (ur.user_id = u.id)
| join role r on (r.id = ur.role_id)
| where r.authority in ($s)
| order by u.username
""".stripMargin).as(parser.*)
}
def findAllWithRole(roles: List[String]) = DB.withConnection { implicit c =>
SQL"""
where r.authority in ($roles)
order by u.username
""".as(parser.*)
}