2
如何使用相同的對象製作樞軸? 我有這樣的嘗試,但得到一個MySQL錯誤:蒸氣中的樞軸協議
final class UserParent: Model, PivotProtocol {
var storage = Storage()
typealias Left = User
typealias Right = User
static var leftIdKey: String = "user_id_parent"
static var rightIdKey: String = "user_id_child"
init(row: Row) throws { }
func makeRow() throws -> Row {
let row = Row()
return row
}
}
//MARK: - Preparation
extension UserParent: Preparation {
static func prepare(_ database: Database) throws {
try database.create(self, closure: { builder in
builder.id()
builder.int("user_id_parent")
builder.int("user_id_child")
})
}
static func revert(_ database: Database) throws {
try database.delete(self)
}
}
,然後我有這個我的用戶對象
var users: Siblings<User, User, UserParent> {
return siblings()
}
上,但我得到這個MySQL錯誤
[MySQL Error: Unknown column 'user_parents.user_id' in 'where clause']
在此PR中添加了創建自定義鍵的功能:https://github.com/vapor/fluent/pull/251請在此處查看測試:https://github.com/vapor /流利/拉/ 251 /文件#DIFF-b6a7113811c9efca25dcc7e0067dafaaR2 – tanner0101