This is my route :
router.get("answers","delete", Int.parameter) { req -> Future<Response> in
let answerID = try req.parameters.next(Int.self)
guard let _ = getUsername(req) else {
throw Abort(.unauthorized)
}
return Message.query(on: req).filter(\.id == answerID).first().map(to: Response.self) { answer in
guard let answer = answer else {
throw Abort(.notFound)
}
return answer.delete(on: req).map(to: Response.self) { _ in
return req.redirect(to: "/answers")
}
}
}
But for xCode this is Ambiguous without more context .filter(\.id == answerID)
And this is my struct Message :
struct Message: Content, SQLiteUUIDModel, Migration {
var id: UUID?
var username: String
var content: String
var category: String
var question: String
var date: Date
}
I don't understand because I use filters on ids in many other routes and it's the first time I show this error.
I googled this and it seems that the errors shows up when Fluent is not imported but I've already import Fluent
at the top.
I just had time to test your code. If you replace
... .map(to: Response.self) { answer in ....
with
... .flatMap(to:Response.self) { answer in ...
it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With