所以我有模型名称Organization
,User
和App
. 应用程序和用户都属于组织。
final class Organization: Model, Content {
static let schema = "organizations"
@ID(key: .id)
var id: UUID?
@Field(key: "name")
var name: String
@Children(for: \.$organization)
var users: [User]
}
final class App: Model, Content {
static let schema = "apps"
@ID(key: .id)
var id: UUID?
@Field(key: "name")
var name: String
@Parent(key: "organization_id")
var organization: Organization
}
final class User: Model, Content {
static let schema = "users"
@ID(key: .id)
var id: UUID?
@Field(key: "email")
var email: String
@Field(key: "password_hash")
var passwordHash: String
@Parent(key: "organization_id")
var organization: Organization
}
现在,基本上我想做的是,给定一个用户,我想获取属于该用户组织的所有应用程序。
我可以从我的身份验证系统中获取用户,但我所拥有的只是这个查询:
let user = try req.auth.require(User.self)
return App.query(on: req.db).filter(\.$organization.id == user.$organization.id).all()
这将失败并显示错误消息Operator function '==' requires that 'UUID' conform to 'QueryableProperty'
。
我应该怎么做?