内のオブジェクトの配列上のforループI持って、次のケースクラスScalaのオブジェクト
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)
BusinessHours BusinessInputの時間フィールドにある各BusinessHoursinputオブジェクトのDBへの行。
_ <- 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 ObjectからのビジネスIDを使用してbusinessHoursオブジェクトのリストを挿入します。そして、私は私が最初に挿入ビジネスオブジェクトを返すようにしたい:
hours -> Vector(ListMap(weekDay -> 1, startTime -> 07:00, endTime -> 10:00), ListMap(weekDay -> 2, startTime -> 07:00, endTime -> 10:00))
そして今、私は次のエラーを取得しています:
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)
)
ここで時間フィールドがどのように見えるかのプリントアウトであります
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