我使用了postgres的光滑,我有以下两个表:
class Friendships(tag: Tag) extends Table[Friendship](tag, "FRIENDSHIP") {
def userOneId = column[Long]("USER_ONE")
def userTwoId = column[Long]("USER_TWO")
def blocked = column[Boolean]("BLOCKED", O.Default(false))
def createdAt = column[Timestamp]("CREATED_AT")
def * = (userOneId, userTwoId, blocked, createdAt) <>(Friendship.tupled, Friendship.unapply)
}
class Users(tag: Tag) extends Table[User](tag, "USERS") {
def id = column[Long]("USER_ID", O.PrimaryKey, O.AutoInc)
def firstName = column[String]("FIRST_NAME", O.NotNull)
def lastName = column[String]("LAST_NAME", O.NotNull)
def phone = column[String]("PHONE_NUMBER", O.NotNull)
def lat = column[Double]("LATITUDE", O.NotNull)
def long = column[Double]("LONGITUDE", O.NotNull)
def updatedAt = column[Timestamp]("UPDATED_AT")
def createdAt = column[Timestamp]("CREATED_AT")
def * = (id.?, firstName, lastName, phone, lat, long, updatedAt, createdAt) <>(User.tupled, User.unapply)
}
I'd like to know what happens if I do not have a primary key like in the Friendships table?
更重要的是,我想知道如何在userOneId
和userTwoId
上创建复合主键作为id
表中Users
字段的外键,并设置外键约束,以便在删除userOneId
或userTwoId
时删除友谊记录。
谢谢:)