1

从下面的 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)

}

要获得一个 assignmentmet 和链接到它的表单,您可以这样做:

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...)),但这会导致代码效率低下,并且真的错过了使用对象的重点。

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

4

1 回答 1

0

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

于 2012-10-18T17:31:55.397 回答