I have a table like this:
object Addresses extends Table[AddressRow]("address") { def id = column[Int]("id", O.PrimaryKey, O.AutoInc) def street = column[String]("street") def number = column[String]("number") def zipcode = column[String]("zipcode") def city = column[String]("city") def country = column[String]("country") def geoLocationId = column[Int]("geo_location_id", O.Nullable) // Foreign keys. def geoLocation = foreignKey("fk_geo_location", geoLocationId, GeoLocations)(_.id) // Rest of my code. ... }
where is my case class:
case class AddressRow( id: Option[Int] = None, street: String, number: String, zipcode: String, city: String, country: String, geoLocationId: Option[Int])
As you can see, geoLocation is an optional foreign key ....
I cannot find a way to describe this βOptionalβ in my foreign key definition.
I tried:
def geoLocation = foreignKey("fk_geo_location", geoLocationId.asColumnOf[Option[Int]], GeoLocations)(_.id)
but I get:
Called: scala.slick.SlickException: you cannot use the Apply column Cast function in a foreign key constraint (only columns with names are allowed)
Does anyone have a suggestion?
source share