After learning how to map a database table to a Scala class using Record, we will learn how to take the next step, which is mapping a one-to-many relationship using Record.
We are going to modify the project from the last recipe. You can duplicate the project or modify it; it is your choice.
Create a table called
phones
:create table phones ( id serial primary key, number varchar(15), contact bigint )
Add the following import statements in the
Boot.scala
file:import net.liftweb.http.S import net.liftweb.util.LoanWrapper import net.liftweb.squerylrecord.RecordTypeMode._
Add the following code into the
boot
method in theBoot.scala
file:S.addAround(new LoanWrapper { override def apply[T](f: => T): T = inTransaction(f)
Now, you won't need to invoke the inTransaction
or transaction
methods.