问题
From the Lift-Web Mapper model below, how do I access the fields under 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)
}
To get an assignmet and the forms linked to it, you do this:
val assignments = Assignments.find(By(Assignment.id, 123))
assignments match {
case Full(as) => {
val forms = as.forms
.....
But I have no idea how to navigate to the order, readonly, required...
fields under AssignmentformLink
.
I realise I can search for the link manually, ie. AssignmentformLink.find(By(form...),By(assignment...))
, but this will result in inefficient code and really misses the point of using objects.
I need to be able to navigate from the form to the link table's fields.
回答1:
Don't know if this is the correct approach, but assignments.joins
returns a list of the join table records.
来源:https://stackoverflow.com/questions/12843590/how-do-i-access-the-fields-of-a-link-table-with-lift-mapper