光滑的DBIO序列无法编译 [英] Slick DBIO sequence failing to compile
问题描述
我正在尝试将模型ProductCategory
对象保存在数据库中.保存时,categoriesId
是Seq
.
I am trying to save model ProductCategory
object in database. While saving it,categoriesId
is a Seq
.
case class ProductCategory(productItemId: ProductItemId, categoryies: CategoryId, filterName: FilterName)
/*Inside another object starts*/
def saveCategoriesId(productItemId: ProductItemId, categoryId: Seq[CategoryId], filterName: FilterName):
Future[Seq[ProductItemId]] =
db.run({
DBIO.sequence(categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
})
def save(productCategory: ProductCategory): DBIO[ProductItemId] =
query returning query.map(_.productItemId) += productCategory
出现以下错误:
[error] /Users/vish/Work/jd/app/service/ProductCategoryService.scala:20:35: type mismatch;
[error] found : Seq[slick.dbio.DBIOAction[models.ProductItemId,slick.dbio.NoStream,Nothing]]
[error] required: Seq[slick.dbio.DBIOAction[models.ProductItemId,slick.dbio.NoStream,E]]
[error] DBIO.sequence(categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
Playframework版本是2.6.此问题不是此的重复项.此问题已被阻止进一步发展.回答时请说明是否正确保存categoriesId
Playframework version is 2.6. This question is not duplicate of this.This issue has blocked the further development. While answering please comment if it correct way of saving categoriesId
推荐答案
通常在Scala中,编译错误found: Nothing, required: E
表示编译器无法推断某些类型.尝试手动指定一些类型参数
Normally in Scala compile error found: Nothing, required: E
means that compiler couldn't infer some types. Try to specify some type parameters manually
db.run({
DBIO.sequence[ProductItemId, Seq, All](categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
})
或
db.run({
DBIO.sequence(categoryId.map[DBIO[ProductItemId], Seq[DBIO[ProductItemId]]](id => save(ProductCategory(productItemId, id, filterName))))
})
或引入局部变量(然后编译器将能够自行推断类型)
or introduce a local variable (then compiler will be able to infer types itself)
val actions = categoryId.map(id => save(ProductCategory(productItemId, id, filterName)))
db.run({
DBIO.sequence(actions)
})
这篇关于光滑的DBIO序列无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!