Working with link tables in Lift Mapper

11 views
Skip to first unread message

Jacobus

unread,
Oct 12, 2012, 6:58:32 AM10/12/12
to lif...@googlegroups.com
Good day,

Apologies for asking this question again, but I really need to know how to do this. I asked this question earlier, but it turned into a discussion for if this was good design or not, which is not what I am after at this point.

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.

Kind regards,
Jacobus

Naftoli Gugenheim

unread,
Oct 12, 2012, 4:59:11 PM10/12/12
to lif...@googlegroups.com
Hi, I replied on your other thread just before.



--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
 
 
 

Reply all
Reply to author
Forward
0 new messages