2012-10-11 57 views
1

從下面的Lift-Web Mapper模型中,如何訪問AssignmentformLink下的字段?如何使用Lift Mapper訪問鏈接表的字段?

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...)),但這會導致代碼效率低下,並且錯過了使用對象的要點。

我需要能夠導航從窗體到鏈接表的字段。

+0

我從來不需要這樣做,也不確定是否有方便的方法,但我已經使用了可以在查詢參數中引用連接表的事實,您可以將它傳遞給'MappedManyToMany' - 例如, 'OrderBy(AssignmentformLink.order,Ascending)'。 –

+0

您當然也可以使用查詢參數在'Assignment'中創建像'readOnlyForms','requiredForms'等對象。我知道,不是你想要的,但可能會讓你接近你想要做的事。 –

+0

感謝您的建議@TravisBrown。我真的很感激你的意見。 – Jack

回答

0

不知道這是否正確,但assignments.joins返回連接表記錄的列表。

相關問題