이것은 다른 자동 증가 질문과 비슷한 질문이지만 autoInc을 정의하기 위해 열 목록을 제공하는 대신 어떻게 든 테이블 참조를 제공해야합니다. 나는 다음주는 스칼라 슬릭 자동 증가 필드
import scala.slick.driver.MySQLDriver.simple._
import play.Logger
import slick.session.Database.threadLocalSession
object PaypalCartItems extends Table[PaypalCartItem]("paypalCartItem") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def itemName = column[String]("item_name")
def sku = column[String]("item_number")
def quantity = column[String]("quantity")
def txnId = column[String]("txn_id")
def url = column[String]("url")
def * = itemName ~ sku ~ quantity ~ txnId ~ url ~ id <> (PaypalCartItem, PaypalCartItem.unapply _)
// I don't want to list out the columns, I need to reference the table
def autoInc = itemName ~ sku ~ quantity ~ txnId ~ url returning id
def insertItems(items: List[PaypalCartItem]): List[PaypalCartItem] = items map { item: PaypalCartItem =>
val newId = PaypalCartItems.autoInc.insert(item)
item.copy(id=newId)
}
}
위의 코드는 컴파일되지 않습니다 MySQL의
을 사용하고 있습니다 : 그것은 당신을 도울 것입니다[error] overloaded method value insert with alternatives:
[error] [TT](query: scala.slick.lifted.Query[TT,(String, String, String, String, String)])(implicit session: scala.slick.session.Session)Seq[Int] <and>
[error] (value: (String, String, String, String, String))(implicit session: scala.slick.session.Session)Int
[error] cannot be applied to (PaypalCartItem)
[error] val newId = PaypalCartItems.autoInc.insert(item)
"어떻게 든 테이블 참조를 제공해야합니다."라는 의미가 확실하지 않습니다. – pedrofurla