如何使用Lift Mapper访问链接表的字段?

时间:2012-10-11 15:49:26

标签: scala lift

从下面的Lift-Web Mapper模型中,如何访问AssignmentformLink下的字段?

object TForm extends TForm with LongKeyedMetaMapper[TForm]

class TForm extends LongKeyedMapper[TForm] with IdPK with ManyToMany {
  def getSingleton = TForm

  object label extends MappedString(this, 40)

  object pattern extends MappedString(this, 200)

  object assignments extends MappedManyToMany(
      AssignmentformLink, AssignmentformLink.assignment, AssignmentformLink.form, TForm)

}

object AssignmentformLink extends AssignmentformLink with LongKeyedMetaMapper[AssignmentformLink] {
  override def dbIndexes = Index(form, assignment) :: super.dbIndexes
}

class AssignmentformLink extends LongKeyedMapper[AssignmentformLink] with IdPK {
  def getSingleton = AssignmentformLink

  object form extends MappedLongForeignKey(this, TForm)

  object assignment extends MappedLongForeignKey(this, Assignment)

  object order extends MappedInt(this)

  object readonly extends MappedBoolean(this)

  object required extends MappedBoolean(this)

  object visible extends MappedBoolean(this)

}

object Assignment extends Assignment with LongKeyedMetaMapper[Assignment]

class Assignment extends LongKeyedMapper[Assignment] with IdPK with ManyToMany {
  def getSingleton = Assignment

  object id_parent extends MappedLong(this)

  object label extends MappedString(this, 40)

  object order extends MappedInt(this)

  object guard extends MappedString(this, 200)

  object forms extends MappedManyToMany(
      AssignmentformLink, AssignmentformLink.assignment, AssignmentformLink.form, TForm)

}

要获取assignmet以及与之关联的表单,请执行以下操作:

val assignments = Assignments.find(By(Assignment.id, 123))

assignments match {
  case Full(as) => {
    val forms = as.forms
.....

但我不知道如何导航到order, readonly, required...下的AssignmentformLink字段。

我意识到我可以手动搜索链接,即。 AssignmentformLink.find(By(form...),By(assignment...)),但这会导致代码效率低下,并且错过了使用对象的重点。

我需要能够从表单导航到链接表的字段。

1 个答案:

答案 0 :(得分:0)

不知道这是否是正确的方法,但assignments.joins会返回连接表记录的列表。