So far, we have learned how to map a table using Record and Squeryl; we've also learned how to create a one-to-many relationship. We will now learn how to create a many-to-many relationship using Record and Squeryl.
You can use any of the projects that we have created in this chapter, or you can start a new one; do whatever fits you best.
Create the following tables:
create table courses ( id serial primary key, name varchar(100) ); create table students ( id serial primary key, name varchar(100) ); create table courses_students ( id serial primary key, course bigint, student bigint );
Create a class called
Student
in themodel
package, as follows:package code.model import net.liftweb.record.{MetaRecord, Record} import net.liftweb.squerylrecord.KeyedRecord import net.liftweb.record.field.{StringField, LongField} import org.squeryl.annotations.Column import org.squeryl.dsl.ManyToMany import net.liftweb.squerylrecord...