我有一张这样的桌子:
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.
...
}
我的案例类是:
case class AddressRow(
id: Option[Int] = None,
street: String,
number: String,
zipcode: String,
city: String,
country: String,
geoLocationId: Option[Int])
如您所见, geoLocation 是一个可选的外键....
我在我的外键定义中找不到任何方法来描述这个“可选”。
我试过像:
def geoLocation = foreignKey("fk_geo_location", geoLocationId.asColumnOf[Option[Int]], GeoLocations)(_.id)
但我收到:
引起:scala.slick.SlickException:不能在外键约束中使用列应用函数转换(只允许命名列)
有人有建议吗?