2

Slick Codegen 是否可以在 之外生成所有映射的案例类${container} trait ,以便它们不继承其类型?也许完全在另一个文件中,即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#SuppliersRowimport 给出了同样的错误。

SuppliersRow如果我在自动生成的外部手动剪切和粘贴案例类,trait Tables它就可以工作!

....

trait Tables {

....
}
case class SuppliersRow(id: Int, userId: Int, name: String)
//EOF
4

1 回答 1

3

将原件附加docWithCode到:EntityTypesuper.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"
        ""
      }
    }
  }

}
于 2015-08-18T10:40:01.567 回答