Bla*_*man 7 scala playframework slick
为了节省我必须创建这么多方法,我尝试将Option's传递给我的方法,然后检查是否定义了Option,如果是,则应用过滤器.
def getUsers(locationId: Option[Int], companyId: Int, salary: Option[Int]): List[User] = {
val query = for {
u <- users if u.companyId === companyId && (locationId.isDefined && u.locationId === locationId.get) && (salary.isDefined && u.salary >= salary.get)
}
query.list()
}
Run Code Online (Sandbox Code Playgroud)
我收到错误说:
polymorphic expression cannot be instantiated to expected type;
IntelliJ errors are expected Boolean actual Column[Boolean].
Run Code Online (Sandbox Code Playgroud)
这种类型的条款在光滑的查询中是不可能的,或者我只是做错了?
我无法告诉你为什么但这会为我编译:
def getUsers(locationId: Option[Int], companyId: Int, salary: Option[Int]): List[User] = {
val query = for {
u <- users if u.companyId === companyId && locationId.isDefined && u.locationId === locationId.get && salary.isDefined && u.salary >= salary.get
} yield(u)
query.list()
}
Run Code Online (Sandbox Code Playgroud)
请注意,没有括号和你有yield什么,否则返回类型query会Unit.
| 归档时间: |
|
| 查看次数: |
3417 次 |
| 最近记录: |