Last active
November 27, 2019 22:17
-
-
Save NeuralGlue/c0f2c650614dfa09aa7bded04a033711 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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