我需要User通过提供除id某些情况以外的所有值来创建对象的能力,以便该对象负责为其User自身分配一个自动生成的值。
为此,我重载apply方法在随对象,如下所示。但这会导致编译时错误:value tupled is not a member of object。
StackOverflow和其他博客上提到的解决方案不起作用,例如:http : //queirozf.com/entries/slick-error-message-value-tupled-is-not-a-member-of-object
case class User(id: Long, firstName: String, lastName: String, mobile: Long, email: String)
object User {
private val seq = new AtomicLong
def apply(firstName: String, lastName: String, mobile: Long, email: String): User = {
User(seq.incrementAndGet(), firstName, lastName, mobile, email)
}
}
class UserTableDef(tag: Tag) extends Table[User](tag, "user") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def firstName = column[String]("first_name")
def lastName …Run Code Online (Sandbox Code Playgroud)