I use playframework 2.2+slick 2:
my datamodel:
case class User(id:Option[String], firstName:String,secondName:String, addressid:Long)
class UserTable(tag: Tag) extends Table[User](tag, "User") {
def id = column[String]("ID", O.PrimaryKey)
def first_name = column[String]("First_Name")
def second_name=column[String]("Second_Name")
def addID = column[Long]("ADDRESS")
def home_address=foreignKey("ha_FK", addID, address)(_.id)
def * = (id.?, first_name, second_name, email, roles.?, profile,datebirth,addID)<>(User.tupled,User.unapply)
}
val user=TableQuery[UserTable]
}
case class Address(id:Long, state:String, city:String, street:String, unit: String, zip:String)
class AddressTable(tag:Tag) extends Table[Address](tag, "Address"){
def id = column[Long]("ID", O.PrimaryKey)
def state=column[String]("State")
def city=column[String]("City")
def street=column[String]("Street")
def unit=column[String]("Unit")
def zip=column[String]("zip")
def * = (id, unit, street, city, state, zip)<>(Address.tupled,Address.unapply)
}
val address = TableQuery[AddressTable]
I have a form to fill both user information and his address information. I do not know how to mapping them:(of course here is fake code)
val fullForm = Form(
mapping(
"User.first_name" -> text(),
"User.second_name" -> text(),
"User.id"-> ignored,
"User.addID"->ignored,
"Address.id"->ignored,
"Address.state"->text,
"Address.city"->text
...
)(User.apply, Address.apply)(User.unapply, Address.apply)
)
How to mapping a Form to multi-data-models here? Can you give this case an example?