tux*_*dna 2 scala playframework slick playframework-2.2
我想在whereSlick查询的方法中添加两个子句.我有代码:
val users = TableQuery[Users]
val actions = TableQuery[Acts]
val filteredUsers = users.where(.....) // Some condition
val acts = actions.where(_.domain === 10)
val ownerAct = acts.where(_.owner in filteredUsers)
val assigneeAct = acts.where(_.assignee in filteredUsers)
Run Code Online (Sandbox Code Playgroud)
我想获取属于过滤用户assignee或ownerer过滤用户的操作.我希望代码是这样的:
val users = TableQuery[Users]
val actions = TableQuery[Acts]
val filteredUsers = users.where(.....) // Some condition
val acts = actions.where(_.domain === 10)
val ownerOrAssigneeAct = acts.where(_.owner in filteredUsers).
or(_.assignee in filteredUsers)
Run Code Online (Sandbox Code Playgroud)
如何使用Scala Slick 2.0在.where()中生成这样的OR查询?
有几件事,首先要使用in你的查询必须返回一些东西,而不是
val filteredUsers = users.where(.....)
Run Code Online (Sandbox Code Playgroud)
应该(取自这个答案):
val filteredUsers = users.filter(/* condition */).map(_.id)
Run Code Online (Sandbox Code Playgroud)
假设你想匹配id,那么你可以简单地使用匿名函数组成条件:
val ownerOrAssigneeAct =
acts.filter(act => act.domain === 10 && (act.owner in filteredUsers || act.assignee in filteredUsers))
Run Code Online (Sandbox Code Playgroud)
请注意,我没有使用,where因为它已被弃用,请filter改用.
| 归档时间: |
|
| 查看次数: |
2904 次 |
| 最近记录: |