我有这样的Scala代码,但它并没有给排序列表:如果我只用这条线之下我得到的排序列表没有排序斯卡拉光滑查询
val itemList = items.sortBy(_.name).filter(_.categoryId === catId).drop(start)
是
def getItemsByCategoryId(catId: Long, start: Int = 0, limit: Option[Int] = None): Future[Seq[(Item, Seq[String])]] = {
val itemList = items.sortBy(_.name).filter(_.categoryId === catId).drop(start)
val q = for {
(j, pair) <- itemList joinLeft (groups join tags on (_.tagId === _.id)) on (_.id === _._1.itemId)
} yield (j, pair)
db.run(q.result).map { (row) =>
row.groupBy(_._1).map { x =>
val tags = x._2.map(_._2).flatten
(x._1, tags.map(_._2.keyword))
}.toSeq
}
}
join/groupBy操作以某种方式影响排序?
是的,他们做了,并在一个非常大的方式。所以如果你想要排序的结果,那么你将不得不再次排序。 –