Scala、Play 框架、Slick:在枚举字段上使用过滤器进行数据库连接查询

Scala, Play framework, Slick: db join query with filter on enumeration field

我有一个带连接的 Slick 查询,在枚举字段上有一个过滤器,为此我得到以下编译错误:

[error] /Users/someuser/SomeApp/app/com/somePackage/SomeDAO.scala:190:84: value === is not a member of slick.lifted.Rep[com.somePackage.models.MyCustomEnum.MyCustomEnum]
[error]           myCustomEnumTbl.userId === userTbl.id && myCustomEnumTbl.selectionType === MyCustomEnum.FOOD
[error]                                                                                  ^

代码片段:

var userQuery = for {
  (user, selection) <- Users.filter(_.id === userId).join(selectionTableDAO.getTable).on {
  (myCustomEnumTbl,userTbl) => myCustomEnumTbl.userId === userTbl.id && myCustomEnumTbl.selectionType === MyCustomEnum.FOOD
} yield (user, selection)
val userRes = db.run(userQuery.result)

过滤枚举字段的正确方法是什么?

我能够通过为枚举字段定义隐式映射来解决这个问题:

implicit val CustomSelectionTypeEnumsTypesMapper = MappedColumnType.base[MyCustomEnum, String](
  e => e.toString,
  s => MyCustomEnum.withName(s)
)