У меня есть 3 таблицы, которые определены как 3 тематических класса. Продавец и покупатель имеют один-ко-многим отношения с адресом. Можно ли как-то использовать один внешний ключ в таблице адресов, чтобы указывать на таблицу продавца и покупателя, вместо использования двух внешних ключей? Я не уверен, как написать сопоставления. Вот что я получил:
case class Seller(id: Long, name: String)
case class Buyer(id: Long, name: String)
case class Address(id: Long, street: String, city: String, userId: Long)
class SellerTableDef(tag: Tag) extends Table[Seller](tag, "seller") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
override def * = (id, name) <> (Seller.tupled, Seller.unapply)
}
class BuyerTableDef(tag: Tag) extends Table[Seller](tag, "buyer") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
override def * = (id, name) <> (Buyer.tupled, Buyer.unapply)
}
class AddressTableDef(tag: Tag) extends Table[Address](tag, "address") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def street = column[String]("street")
def city = column[String]("city")
def userId = column[Long]("user_id")
//!!!Can I use one foreign key to point to both the Seller and the Buyer table?!!!
def user = foreignKey("user_FK", userId, ???)(_.id)
}
Большое спасибо.