Hi Tiger,
the proper way to do relationships with Slick is NOT to do nesting (user
having an address member) but using a foreign key instead (user having
an addressId member and a corresponding address object). Among other
things this makes the loading strategy (lazy, eager, ...) explicit in
user code and does not complicate Slick's api and implementation with
the need to have configuration options for loading strategies of related
objects. This is a fundamental design choice that makes Slick different
from ORMs. I will publish a proper documentation section about
relationships in Slick in the near future. The message regarding type
mappers refers to a feature of Slick that allows you to integrate your
own column types into Slick, i.e. values that map to exactly one column.
Instead of user having an address member, you either get the address
using the foreign key:
val user = ... // <- your user object
val address = Query(Addresses).filter(_.id === user.addressId).first
Or you write a more universal function, that even works for users which
you have not been materialized in memory (in other words queries of
users). It takes a querys of users and returns a query of addresses or
(user,address) tuples. E.g. something like this
def joinUserAddress( users:Query[Users,User] = Query(Users),
address=Query[Addresses,Address] = Query(Addresses) ) = for( u <- users;
a <- addresses; if u.address_id ===
a.id ) yield (u,a)
And then you can fetch the address of a users in the place where you
need it like this:
val userQuery = ... // <- some query finding one or more user objects
val (user,address) = joinUserAddress( users=userQuery ).first
Also see our ScalaDays 2013 talk
http://slick.typesafe.com/docs/ .
For a one-to-one relationship you can alternatively consider to put all
columns into a single table. In this case you can actually map them to
nested case class structure as I described here:
http://stackoverflow.com/questions/18572084/how-to-combine-multiple-columns-in-one-case-class-field-when-using-lifted-embedd/18591234
Chris
--
Slick Team