In Chapter 22 “Users and Categories”, just before the last change in the code for acronymHandler to add the categories, running TILApp produces the desired result when tapping an acronym link - the acronym info page is displayed. When you change the code from the following:
func acronymHandler(_ req: Request) throws → Future {
return try req.parameter(Acronym.self).flatMap(to: View.self) { acronym in
return acronym.creator.get(on: req).flatMap(to: View.self) { creator in
let context = AcronymContext(title: acronym.long, acronym: acronym, creator: creator)
return try req.leaf().render(“acronym”, context)
}
}
}
to the following:
func acronymHandler(_ req: Request) throws → Future {
return try req.parameter(Acronym.self).flatMap(to: View.self) { acronym in
return try flatMap(to: View.self, acronym.creator.get(on: req), acronym.categories.query(on: req).all()) { creator, categories in
let context = AcronymContext(title: acronym.long, acronym: acronym, creator: creator, categories: categories.isEmpty ? nil : categories)
return try req.leaf().render(“acronym”, context)
}
}
}
after adding categories to the AcronymsContext struct, the link from an acronym is broken. (In the browser, you get “Oops: This parent relationship could not be resolved” and the message in the Xcode console is “[ ERROR ] FluentError.parentRequired: This parent relationship could not be resolved (Parent.swift:38)”.
Remove the code for the categories from acronymHandler and the app works again without errors.
The code downloaded from Chapter 22 in the video course shows the same issue.