可以使用光滑的codegen生成${container} trait
之外的所有映射的case类,以便它们不会继承它的类型吗?也许在另一个文件中,即Models.scala
?
// SuppliersRowsDAA.scala
import persistence.Tables
object SuppliersRowsDAA {
case class Save(sup: Tables.SuppliersRow)
}
我收到此编译错误:
[error] /app/src/main/scala/persistence/dal/SuppliersDAA.scala:5: type mismatch;
[error] found : persistence.Tables.SuppliersRow
[error] required: SuppliersDAA.this.SuppliersRow
[error] case Save(sup) ⇒ sender ! db.run(Suppliers += sup)
使用Tables#SuppliersRow
导入会产生同样的错误。
如果我手动切割&将SuppliersRow
案例类粘贴到自动生成的trait Tables
之外!
....
trait Tables {
....
}
case class SuppliersRow(id: Int, userId: Int, name: String)
//EOF
有什么想法吗?
答案 0 :(得分:3)
将docWithCode
的原始EntityType
追加到super.packageCode()
:
import slick.codegen.SourceCodeGenerator
import slick.model.Model
import scala.collection.mutable
class CustomizedCodeGenerator(model: Model) extends SourceCodeGenerator(model) {
val models = new mutable.MutableList[String]
override def packageCode(profile: String, pkg: String, container: String, parentType: Option[String]): String = {
super.packageCode(profile, pkg, container, parentType) + "\n" + outsideCode
}
def outsideCode = s"${indent(models.mkString("\n"))}"
override def Table = new Table(_) {
override def EntityType = new EntityTypeDef {
override def docWithCode: String = {
models += super.docWithCode.toString + "\n"
""
}
}
}
}