內的對象的序列環,我有以下案例類斯卡拉對象
case class BusinessInput(userId: String, name: String, location: Point, address: Option[String], phonenumber: Option[String], email: Option[String], hours: Seq[BusinessHoursInput])
而下面BusinessHours案例類:
case class BusinessHoursInput(weekDay: Int, startTime: Time, endTime: Time)
我使用光滑,我試圖加BusinessInput的BusinessHours行添加到BusinessInput的小時字段中的每個BusinessHoursinput對象的數據庫。我曾嘗試以下:
_ <- for(businessHours <- businessInput.hours) BusinessHours += BusinessHoursRow(businessRow.businessId, businessHours.weekDay, businessHours.startTime, businessHours.endTime)
但我被困在下面的錯誤:
value map is not a member of Unit
[error] _ <- for(businessHours <- businessInput.hours) BusinessHours += BusinessHoursRow(businessRow.businessId, businessHours.weekDay, businessHours.startTime, businessHours.endTime)
[error] ^
編輯:
這裏是我的回購的創造功能,在那裏我第一次嘗試插入一個BusinessRow對象,然後從該插入中獲取自動增量的Id,並使用先前插入的業務對象的Business Id插入businessHours對象的列表。然後我想返回業務對象,我第一次插入:
def create(businessInput: BusinessInput): Future[BusinessRow] = db.run(for {
// We create a projection of just the Business Columns, since we're not inserting a value for the id column
businessRow <- (Business.map(b => (b.userId, b.name, b.location, b.address, b.phonenumber, b.email))
// Now define it to return the id, because we want to know what id was generated for the Business
returning Business.map(_.businessId)
// And we define a transformation for the returned value, which combines our original parameters with the
// returned id
into((userIdAndBusiness, id) => BusinessRow(id, userIdAndBusiness._1, userIdAndBusiness._2, userIdAndBusiness._3, userIdAndBusiness._4, userIdAndBusiness._5, userIdAndBusiness._6))
// And finally, insert the business into the database
) +=(businessInput.userId, businessInput.name, businessInput.location, businessInput.address, businessInput.phonenumber, businessInput.email)
// Insert a sequence of BusinessHours objects
_ = for(businessHours <- businessInput.hours) BusinessHours += BusinessHoursRow(businessRow.businessId, businessHours.weekDay, businessHours.startTime, businessHours.endTime)
} yield (businessRow)
)
這裏是打印出來的是什麼時間場的樣子:
hours -> Vector(ListMap(weekDay -> 1, startTime -> 07:00, endTime -> 10:00), ListMap(weekDay -> 2, startTime -> 07:00, endTime -> 10:00))
,現在我收到以下錯誤:
scala.collection.immutable.ListMap$Node cannot be cast to dao.BusinessHoursInput
我很困惑_ <-',你想做什麼? – DanGordon
請首先看看[Scala collections doc](https://docs.scala-lang.org/overviews/collections/overview.html),以及Scala哲學如何關於不變性(而不是像'+ = ')。 – cchantep