Lift Mapper 或记录框架中的继承

发布于 2024-09-17 19:38:40 字数 81 浏览 8 评论 0原文

有没有一种方法可以使用 Mapper o Record Framework 在 Lift 中定义正确的继承模型,其中父类有一张表,每个子类有一张表?

Is there a way to define proper a inheritance model in Lift using Mapper o Record Framework where there is a table for the parent class and one table for each son?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脸赞 2024-09-24 19:38:40

假设您希望使用继承以便能够在每个子类中使用相同的映射字段,我通过使用这些字段的特征来解决这个问题:

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
}

Assuming you want to use inheritance to be able to use the same mapped fields in each of the subclasses, I've approached this by using a trait for those fields:

trait SuperFields[T <: Mapper[T]] {
  self: T =>
  object DESCRIPTION extends MappedString[T](this, 255)
  object BRAND extends MappedString[T](this, 50)
  // etc
}

Then each Mapper/MetaMapper will extend SuperFields, but define their own database table and connection identifiers:

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
}

And:

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文