Skip to content

Instantly share code, notes, and snippets.

@NeuralGlue
Last active November 27, 2019 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeuralGlue/c0f2c650614dfa09aa7bded04a033711 to your computer and use it in GitHub Desktop.
Save NeuralGlue/c0f2c650614dfa09aa7bded04a033711 to your computer and use it in GitHub Desktop.
// assuming a route such as /parents/Parent.parameter/children/
func addChildtoParent(_ req: Request) throws -> Future<Child> {
return try flatMap(
to: Child.self, // what we will get back
req.parameters.next(Parent.self), // an already existing Parameter conforming instance
req.content.decode(Child.self)) { // a Content conforming instance
parent, child in
child.parentId = try parent.requireId()
child.save(on: req)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment