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

Mapping embedded objects

When working with document-based databases such as MongoDB, instead of using a one-to-many relationship to link to classes that represent two tables in the database—such as contacts and phones—we can map both objects Contact and Phone. Then, instead of storing them in two different collections, we embed the phone object into the contact object. In the following recipe, we will learn how to embed one object into another.

Getting ready

We'll keep evolving the project from the previous recipe.

How to do it...

Carry out the following steps:

  1. Create a new file named Phone.scala in src/main/scala/code/model with the following code:
    package code.model import net.liftweb.mongodb.record._ import net.liftweb.record.field.StringField class ...

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