我想使用 scalaquery / slick 在代表 1:n 关系的 2 个表中插入行。
这些表定义如下:
object CompanyBaseTable extends Table[CompanyBaseTableEntry]("company") {
def id = column[Int]("id", O PrimaryKey, O AutoInc)
}
object ProductCatalogueTable extends Table[ProductCatalogueEntry]("product_catalogue") {
def cid = column[Int]("id", O NotNull)
def pid = column[Long]("pid", O NotNull)
def company = foreignKey("company_fk", cid, CompanyBaseTable)(_.id)
}
我想在一个事务中插入 1:n 关系,但我不知道如何使用 ScalaQuery 来实现。在 JDBC 3 中,您可以从语句中获取生成的 ID ,但我看不到语句在 ScalaQuery API 中暴露的位置,我也看不到直接访问此信息的方法。