我遇到了过滤slick-3中的数字列表的条件。这是我的实体。
case class Company(id:Long, name: String, companyTypeId: Option[List[Long]] = None)
implicit def GetResultCompany(implicit e0: GR[Long], e1: GR[String], e2: GR[Option[List[Long]]]): GR[Company] = GR{
prs => import prs._
CompanyTest.tupled((<<[Long], <<[String],<<?[List[Long]]))
}
class CompanyTable(_tableTag: Tag) extends Table[Company](_tableTag, Some("base"), "Company") {
def * = (id, name,companyTypeId) <> (CompanyTest.tupled, CompanyTest.unapply)
def ? = (Rep.Some(id), Rep.Some(name), companyTypeId).shaped.<>({r=>import r._; _1.map(_=> CompanyTest.tupled((_1.get, _2.get _3)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
val id: Rep[Long] = column[Long]("CompanyId", O.AutoInc, O.PrimaryKey)
val name: Rep[String] = column[String]("Name", O.Length(250,varying=true))
val companyTypeId: Rep[Option[List[Long]]] = column[Option[List[Long]]]("CompanyTypeId", O.Length(19,varying=false), O.Default(None))
}
lazy val companyTable = new TableQuery(tag => new CompanyTable(tag))
我想搜索companyTypeId
,Option[List[Long]]
我尝试按companyTable.filter(_.companyTypeId === Some(List(1,2)))
进行操作,但获取Vector()
并且表格中有一行数据,其中companyTypeId为{1}。我使用的是Postgres数据库。
提前致谢。
答案 0 :(得分:2)
可能你可以这样试试:
companyTable.filter(_.companyTypeId inSet(Traversable(List(1,2))))
// the above query filters rows with values in the given list