内的对象的序列环,我有以下案例类斯卡拉对象
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