在两列上滑动外键

时间:2015-04-17 13:59:20

标签: postgresql scala slick slick-2.0

我使用了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?

更重要的是,我想知道如何在userOneIduserTwoId上创建复合主键作为id表中Users字段的外键,并设置外键约束,以便在删除userOneIduserTwoId时删除友谊记录。

谢谢:)

0 个答案:

没有答案