O'Reilly logo

Lift Application Development Cookbook by Gilberto T. Garcia Jr.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating many-to-many relationships

Many-to-many relationships are also very common in real-world applications. In this recipe, we will learn how to use Mapper to create such relationships. To do this, we will create a model for a school where we can have one student attending many subjects and one subject having many students.

Getting ready

You can use any of the projects we have used in the previous sections of this chapter. It is up to you whether to change an existing project or duplicate it.

How to do it...

To create a many-to-many relationship, carry out the following steps:

  1. Create a class called Student in the model package with the following code:
    package code.model import net.liftweb.mapper._ class Student extends LongKeyedMapper[Student] with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required