From 3d118f4020a298ee82eca33cf70e6ca0974341a6 Mon Sep 17 00:00:00 2001 From: Andrei Patru Date: Fri, 14 Sep 2018 17:02:36 -0700 Subject: [PATCH 1/2] Specify that conformance to is necessary before performing a query --- 3.0/docs/fluent/getting-started.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/3.0/docs/fluent/getting-started.md b/3.0/docs/fluent/getting-started.md index ee3567e5..f6c2afcf 100644 --- a/3.0/docs/fluent/getting-started.md +++ b/3.0/docs/fluent/getting-started.md @@ -165,7 +165,13 @@ Server starting on http://localhost:8080 ## Performing a Query -Now that you have created a model and a corresponding schema in your database, let's make your first query. +First, we must ensure that our `User` object conforms to the `Content` type. This will ensure that the object can be encoded and decoded from HTTP messages. You get this conformance for free with any `Model` objects, so implementing this is straightforward: + +```swift +extension User: Content { } +``` + +Now that you have created a model, made it conform to `Content` and created a corresponding schema in your database, let's make your first query. ```swift router.get("users") { req in From fdd66d7762ca8197b57b6229baade0ca48894c83 Mon Sep 17 00:00:00 2001 From: Andrei Patru Date: Sun, 16 Sep 2018 18:51:55 -0700 Subject: [PATCH 2/2] Added Content extension for user in Creating a Model section --- 3.0/docs/fluent/getting-started.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/3.0/docs/fluent/getting-started.md b/3.0/docs/fluent/getting-started.md index f6c2afcf..a2535437 100644 --- a/3.0/docs/fluent/getting-started.md +++ b/3.0/docs/fluent/getting-started.md @@ -79,10 +79,14 @@ final class User: <#Database#>Model { self.age = age } } + +extension User: Content { } ``` The example above shows a simple model representing a user. You can make both structs and classes a model. You can even conform types that come from external modules. The only requirement is that these types conform to `Codable`, which must be declared on the base type for synthesized (automatic) conformance. +*Note:* `Content` conformance will ensure that the object can be encoded and decoded from HTTP messages. This will be necessary when performing a query. + Take a look at [Fluent → Model](models.md) for more information on creating models with custom ID types and keys. ## Configuring the Database @@ -165,14 +169,6 @@ Server starting on http://localhost:8080 ## Performing a Query -First, we must ensure that our `User` object conforms to the `Content` type. This will ensure that the object can be encoded and decoded from HTTP messages. You get this conformance for free with any `Model` objects, so implementing this is straightforward: - -```swift -extension User: Content { } -``` - -Now that you have created a model, made it conform to `Content` and created a corresponding schema in your database, let's make your first query. - ```swift router.get("users") { req in return User.query(on: req).all()