【发布时间】:2018-05-11 09:14:03
【问题描述】:
我想知道如何使用 Fluent 和 FluentMySQL 在 Vapor 3 中创建多对多关系,如 Vapor 2 docs 中所述
遗憾的是,docs for Vapor 3 尚未更新,Pivot 协议的实现已更改。
这是我想要做的:我有两个课程,User 和 Community。一个Community 有members 和Users 可以是多个Communitys 的成员。
目前,我的代码如下所示:
import Vapor
import FluentMySQL
final class Community: MySQLModel {
var id: Int?
//Community Attributes here
}
final class User: MySQLModel {
var id: Int?
//User Attributes here
}
extension Community {
var members: Siblings<Community, User, Pivot<Community, User>> {
return siblings()
}
}
但是,这会导致以下编译器错误:
Cannot specialize non-generic type 'Pivot' 和 Using 'Pivot' as a concrete type conforming to protocol 'Pivot' is not supported。
我看到有一个名为ModifiablePivot 的协议扩展,但我不知道如何使用它,因为任何地方都没有文档或示例代码。
感谢任何帮助。提前致谢!
【问题讨论】: