1
我试图找到一个光滑Table
,其主键执行插入的方式是自动递增,但强制主键的映射情况下类的值。即给定:插入的表pirmary键自动递增
case class Foo(id: Int, name: String)
class FooTable(tag: Tag) extends Table[Foo](tag, "foo") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def * = (id, name) <> (Foo.tupled, Foo.unapply)
}
val foos = TableQuery[FooTable]
如果我通过
db.run(foos += Foo(123,"bar"))
做定期插入它将设置id
到任何下一自动递增值,而不是将其设置为123是否有语法迫使id
在提供案例类Foo
被设置为值?
你想在什么争食ID的情况下,会发生什么? – mfirry
@mfirry此代码为试验过程中加载初始数据。我不打算使用此功能,在生产代码为您精确指定的原因 –