In one of my route (update function) I am trying to:
- look for a model in the database
- if found, update one of its parent field
- update the model on the database.
Here is the snippet:
@Sendable
func update(req: Request) async throws -> HTTPStatus {
print("request update : \(req.body.string ?? "empty")")
let photo = try req.content.decode(PhotoDTO.self)
if let pic = try await Photo.find(photo.id, on: req.db) {
print ("photo found size \(pic.pic.count)b")
pic.$waste.id = photo.waste
do {
try await pic.update(on: req.db)
print("pic saved")
} catch {
print("could not save \(pic.id!) \(error)")
}
return .ok
} else {
throw Abort(.badRequest, reason: "photo not found")
}
}
Every thing seem to work fine until pic.update(on: req.db) as one can see on the console log:
[ INFO ] POST /wastes/update [request-id: 8947C238-21E3-4AF3-8F1B-EE318E4CBB00]
request update : {"waste":"1D37656C-B12E-437B-A929-E7AF7CFBC86A","id":"EE56E014-1793-4113-9440-63CEDF50E8B6"}
photo found size 538528b
But then nothing happens. The model is not updated and there is no error thrown.
I suppose there must some stupid mistake somewhere but I am unable to find out where. Anyone has an idea what could cause this ?