我正在尝试获取消息列表,包括所述消息的所有附件。到目前为止,我不得不使用从AttachmentsEntity到MessageEntity的外键来滑动实体:MessageEntity和AttachmentEntity。
我试图将这两个结果分组,然后以一种方式将每个消息与附件列表选项相关联
val messages = TableQuery[MessageLifted]
val messagesAndAttachmentsLeftJoin = messages joinLeft piecesJointes on {
(_msg, _pj) => _msg.id === _pj.idMessage
}
val messagesAndAttachments = messagesAndAttachmentsLeftJoin .groupBy(_._1).map{ case (msg, req) => (msg, req.map(_._2)) }
def getMessagesConversation(isDemo: Boolean,
identifUser: String,
conversationId: String)(implicit messages: Messages): Future[List[Message]] = dbRepository.perform(isDemo) {
val messages = messagesAndAttachments.result.map(_.map {
case (message) => {
entityToMessage(message)
}
}.toList)
我希望有一个类型为List [tuple2(Message,List [Attachment])]的对象,但出现以下错误:
/root/projects/digifact/server/digifact/app/repositories/digifact/messagerie/MessagerieRepository.scala:146: No matching Shape found.
[error] Slick does not know how to map the given types.
[error] Possible causes: T in Table[T] does not match your * projection,
[error] you use an unsupported type in a Query (e.g. scala List),
[error] or you forgot to import a driver api into scope.
[error] Required level: slick.lifted.FlatShapeLevel
[error] Source type: (repositories.digifact.documentation.MessageLifted, slick.lifted.Query[slick.lifted.Rep[Option[repositories.digifact.documentation.PieceJointeLifted]],Option[repositories.digifact.documentation.PieceJointeEntity],[+A]Seq[A]])
[error] Unpacked type: T
[error] Packed type: G
[error] private val messagesAndAttachments = messagesAndAttachmentsLeftJoin.groupBy(_._1).map{ case (msg, req) => (msg, req.map(_._2))}
有帮助吗?