我想查询在兄弟姐妹字段中包含某些用户的聊天。
简化模型:
final class Chat: Model, Content {
@Siblings(through: ChatUser.self, from: \.$chat, to: \.$user)
var users: [User]
}
final class User: Model, Content {
@Siblings(through: ChatUser.self, from: \.$user, to: \.$chat)
var chats: [Chat]
}
我的获取路线:
func fetch(req: Request) throws -> EventLoopFuture<[Chat]> {
let user = try req.auth.require(User.self)
return Chat
.query(on: req.db)
.filter("users", .contains(inverse: false, .anywhere), user)
.all()
}
我明白了[ ERROR ] server: column chats.users does not exist (errorMissingColumn)
我怎样才能以正确的方式做这样的过滤器?