有没有办法使用Mapper o Record Framework在Lift中定义适当的继承模型,其中有一个父类表和一个每个子表?
答案 0 :(得分:8)
假设您想使用继承来在每个子类中使用相同的映射字段,我通过对这些字段使用特征来解决这个问题:
trait SuperFields[T <: Mapper[T]] {
self: T =>
object DESCRIPTION extends MappedString[T](this, 255)
object BRAND extends MappedString[T](this, 50)
// etc
}
然后每个Mapper / MetaMapper都会扩展SuperFields,但是定义自己的数据库表和连接标识符:
class Product extends Mapper[Product] with SuperFields[Product] {
override def getSingleton = Product
}
object Product extends Product with MetaMapper[Product] {
override def dbTableName = "PRODUCT"
override def dbDefaultConnectionIdentifier = SomeConnection
}
和
class Service extends Mapper[Service] with SuperFields[Service] {
override def getSingleton = Service
}
object Service extends Service with MetaMapper[Service] {
override def dbTableName = "SERVICE"
override def dbDefaultConnectionIdentifier = SomeOtherConnection
}