を見てください。まず、階層を表にマップする方法を見つけます。この場合、私はその型を格納する列を使用しています。しかし、あなたは他のいくつかのトリックを使うこともできます。あなたは次の操作を行うことができ、特定のサブタイプを決定するために
今
trait Base {
val a: Int
val b: String
}
case class ChildOne(val a: Int, val b: String, val c: String) extends Base
case class ChildTwo(val a: Int, val b: String, val d: Int) extends Base
class MyTable extends Table[Base]("SOME_TABLE") {
def a = column[Int]("a")
def b = column[String]("b")
def c = column[String]("c", O.Nullable)
def d = column[Int]("d", O.Nullable)
def e = column[String]("model_type")
//mapping based on model type column
def * = a ~ b ~ c.? ~ d.? ~ e <> ({ t => t match {
case (a, b, Some(c), _, "ChildOne") => ChildOne(a, b, c)
case (a, b, _, Some(d), "ChildTwo") => ChildTwo(a, b, d)
}}, {
case ChildOne(a, b, c) => Some((a, b, Some(c), None, "ChildOne"))
case ChildTwo(a, b, d) => Some((a, b, None, Some(d), "ChildTwo"))
})
}
}
:
Query(new MyTable).foreach {
case ChildOne(a, b, c) => //childone
case ChildTwo(a, b, d) => childtwo
}
スリックは_not_ ORMです!継承を伴うORMのモデルの周りに設計されたスキーマを持っているならば、あなたはSlickでそれを使用しようとすると、インピーダンスのミスマッチの問題全体を逆にしてしまうでしょう... –
私はそれがORMでないことを知っていますしかし、行のいくつかのフォームを与えるフレームワークの場合<->オブジェクトのマッピング、私は疑問に思う継承のようなケース –