lift中如何做多态关系?

发布于 2024-10-18 15:04:07 字数 1068 浏览 1 评论 0原文

我是 Lift 和 scala 的新手,正在尝试做一些事情。 目前我想与 lift 创建多态关联 映射器。

这里有一个例子:

我想创建一个类 Entry ,它可以是 n 中任何一个的条目 ListX 对象。我怎样才能让父母和条目成为 多态性? 是否有一种通用的方法来处理这些多态关联 一对多和双向多对多?

class Entry extends BaseModel[Entry] {
  def getSingleton = Entry

  object parent extends MappedBase(this, AnyList)

}

object Entry extends Entry with LongKeyedMetaMapper[Entry] {

}

class ListA extends BaseModel[ListA] with OneToMany[Long, ListA] {
  def getSingleton = ListA

  object entries extends MappedOneToMany(Entry, Entry.parent)

}

object ListA extends ListA with LongKeyedMetaMapper[ListA] {

}

class ListB extends BaseModel[ListB] with OneToMany[Long, ListB] {
  def getSingleton = ListB

  object entries extends MappedOneToMany(Entry, Entry.parent)

}

object ListB extends ListB with LongKeyedMetaMapper[ListB] {

}

class ListC extends BaseModel[ListC] with OneToMany[Long, ListC] {
  def getSingleton = ListC

  object entries extends MappedOneToMany(Entry, Entry.parent)

}

object ListC extends ListC with LongKeyedMetaMapper[ListC] {


} 

I am new to Lift and scala and trying to do some stuff.
in the moment i want to create polymorphic associations with the lift
mapper.

here one example:

i want to create a class Entry what can be an entry in any of the n
ListX objects. How can i accomplish to let parent and entries be
polymorphic?
Is there a generic Way to to these polymorphic associations with
OneToMany & ManyToMany in both directions?

class Entry extends BaseModel[Entry] {
  def getSingleton = Entry

  object parent extends MappedBase(this, AnyList)

}

object Entry extends Entry with LongKeyedMetaMapper[Entry] {

}

class ListA extends BaseModel[ListA] with OneToMany[Long, ListA] {
  def getSingleton = ListA

  object entries extends MappedOneToMany(Entry, Entry.parent)

}

object ListA extends ListA with LongKeyedMetaMapper[ListA] {

}

class ListB extends BaseModel[ListB] with OneToMany[Long, ListB] {
  def getSingleton = ListB

  object entries extends MappedOneToMany(Entry, Entry.parent)

}

object ListB extends ListB with LongKeyedMetaMapper[ListB] {

}

class ListC extends BaseModel[ListC] with OneToMany[Long, ListC] {
  def getSingleton = ListC

  object entries extends MappedOneToMany(Entry, Entry.parent)

}

object ListC extends ListC with LongKeyedMetaMapper[ListC] {


} 

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文