# Server Side Swift with Vapor - Part 22: Challenge: | Ray Wenderlich

**URL:** <https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081>\
**Category:** 🎓 Courses & Articles\
**Created:** [March 6, 2018, 9:27pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081 "2018-03-06T21:27:55Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 15, 2018, 4:03pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/21 "2018-03-15T16:03:35Z")

</div>

Ahh ok that sounds like a MySQL pipelining issue, or similar to the double flatMap issue - I’ve got an issue open on GitHub and it should be fixed when the NIO stuff gets merged in

---

<div class="post-metadata">

**Author:** ![brokenzz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/brokenzz/32/81494_2.png) [@brokenzz](https://forums.kodeco.com/u/brokenzz)\
**Post date:** [March 18, 2018, 5:02pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/22 "2018-03-18T17:02:55Z")

</div>

Hi @0xtim,

Thanks very much for another great tutorial!

I completed the challenge without issues, but when I went to create acronym/category relationship via:  
`POST /api/acronyms/1/categories/1` - I encountered an error - “FluentError.modelNotFound: No model with ID 1 was found (Model.swift:267)”

Both of these endpoints return results without a problem though:  
`GET /api/acronyms/1`  
`GET /api/categories/1`

I suspect this error came about after changing to persisted storage, as it was working before.

I thought perhaps some migration didn’t take place, but I can see all tables in mySql:

```auto
+------------------+
| Tables_in_vapor |
+------------------+
| acronym+category |
| acronyms |
| categories |
| fluent |
| users |
+------------------+

```

Would appreciate any help :).

Thanks!

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 18, 2018, 5:17pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/23 "2018-03-18T17:17:30Z")

</div>

@brokenzz you haven’t done anything wrong! There’s a bug in the current MySQL beta to do with pipelining queries, basically the double `flatMap()` is causing issues. Until this is resolved you can instead split out the parameter extractions:

```swift
func addCategoriesHandler(_ req: Request) throws -> Future<HTTPStatus> {
  return try req.parameter(Acronym.self).flatMap(to: HTTPStatus.self) { acronym in
    return try req.parameter(Category.self).flatMap(to: HTTPStatus.self) { category in
      let pivot = try AcronymCategoryPivot(acronym.requireID(), category.requireID())
      return pivot.save(on: req).transform(to: .ok)
    }
  }
}

```

That should work

---

<div class="post-metadata">

**Author:** ![brokenzz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/brokenzz/32/81494_2.png) [@brokenzz](https://forums.kodeco.com/u/brokenzz)\
**Post date:** [March 18, 2018, 5:28pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/24 "2018-03-18T17:28:37Z")

</div>

@0xtim 👌 Worked like a charm! Thank you! 🙏

---

<div class="post-metadata">

**Author:** ![vinamelody](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vinamelody/32/97385_2.png) [@vinamelody](https://forums.kodeco.com/u/vinamelody)\
**Post date:** [March 26, 2018, 2:25pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/25 "2018-03-26T14:25:54Z")

</div>

Hi, I’m doing the challenge and getting MySQL error however before implementing the fix for `addCategoriesHandler`, I did `vapor update` and suddenly I’m getting build error.

I tried `rm -rf .build/ *.xcodeproj/ Package.resolved && vapor xcode -y` and even git reset `Package.resolved` file but errors are still there. Now it seems that I can’t get the project right anymore ☹, please help!

 ![21%20PM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/c/3/c3adf6ed679383f23547f2ec2e7156fecaae1055.png)

```auto
Vapor Toolbox: 3.1.4
Vapor Framework: 3.0.0-rc.2.2
Xcode Version 9.2 (9C40b)
Toolchain: Swift 4.1 Snapshot 2018-03-11 (a)

```

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 26, 2018, 3:23pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/26 "2018-03-26T15:23:01Z")

</div>

@vinamelody what build error are you getting? If it’s to do with NIO or OpenSSL, make sure you have the latest version of the vapor toolbox (`brew upgrade vapor`) as RC2 requires LibreSSL now and upgrading the toolbox will pull that down

---

<div class="post-metadata">

**Author:** ![vinamelody](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vinamelody/32/97385_2.png) [@vinamelody](https://forums.kodeco.com/u/vinamelody)\
**Post date:** [March 27, 2018, 1:00am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/27 "2018-03-27T01:00:28Z")

</div>

Thanks @0xtim for the tips. `brew upgrade vapor` solved the issues.  
Now, I’m getting new Swift compiler errors 😓

 ![27%20AM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/2/b/2b37bc5f3c5e9d48b3fbf6b1ce3a748bead118fe.png)

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 27, 2018, 7:33am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/28 "2018-03-27T07:33:50Z")

</div>

@vinamelody awesome, that’s easier to fix! Those will be the changes required for RC2 - see [this Gist](https://gist.github.com/0xTim/b372f91c8bd71ea757d1da526058f2d9) for what you need to do, there should only be a few things you need

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 27, 2018, 3:27pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/30 "2018-03-27T15:27:47Z")

</div>

@subhransu @vinamelody would help if I linked it! Have edited the post to add the Gist

---

<div class="post-metadata">

**Author:** ![vinamelody](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vinamelody/32/97385_2.png) [@vinamelody](https://forums.kodeco.com/u/vinamelody)\
**Post date:** [March 28, 2018, 12:38pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/31 "2018-03-28T12:38:25Z")

</div>

After fixing the code errors, upon hitting `/api/acronyms/1/categories/1`, I get this response error:

```auto
{
    "error": true,
    "reason": "Table 'vapor.acronym_category' doesn't exist"
}

```

Both `/api/acronyms` and `/api/categories` work and return the right json

Also, tried doing a fresh database.

```auto
docker stop mysql
docker rmi <docker image id for mysql>
docker run --name mysql -e MYSQL_USER=til -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=vapor -p 3306:3306 -d mysql/mysql-server
docker exec -it mysql mysql -u til -ppassword

```

Followed by `swift package update` with these responses:

```auto
Updating https://github.com/vapor/vapor.git
Updating https://github.com/vapor/fluent-mysql.git
Updating https://github.com/vapor/leaf.git
Updating https://github.com/vapor/template-kit.git
Updating https://github.com/vapor/service.git
Updating https://github.com/vapor/engine.git
Updating https://github.com/vapor/database-kit.git
Updating https://github.com/vapor/core.git
Updating https://github.com/vapor/console.git
Updating https://github.com/vapor/crypto.git
Updating https://github.com/vapor/routing.git
Updating https://github.com/vapor/validation.git
Updating https://github.com/apple/swift-nio.git
Updating https://github.com/apple/swift-nio-zlib-support.git
Updating https://github.com/apple/swift-nio-ssl.git
Updating https://github.com/apple/swift-nio-ssl-support.git
Updating https://github.com/vapor/mysql.git
Updating https://github.com/vapor/fluent.git
Resolving https://github.com/vapor/vapor.git at 3.0.0-rc.2.2.1
Resolving https://github.com/vapor/core.git at 3.0.0-rc.2.4
Resolving https://github.com/vapor/validation.git at 2.0.0-rc.2.1.1
Resolving https://github.com/vapor/mysql.git at 3.0.0-rc.2.1.2
Resolving https://github.com/vapor/console.git at 3.0.0-rc.2.2
Resolving https://github.com/vapor/leaf.git at 3.0.0-rc.2.1
Resolving https://github.com/vapor/fluent-mysql.git at 3.0.0-rc.2.3
Resolving https://github.com/vapor/fluent.git at 3.0.0-rc.2.3
Resolving https://github.com/vapor/template-kit.git at 1.0.0-rc.2.0.3

```

Followed by `vapor xcode -y`, and got this run fail:

```auto
[INFO] Migrating 'mysql' database (FluentProvider.swift:28)
[INFO] Preparing migration 'Acronym' (MigrationContainer.swift:50)
⚠️ [FluentError.reflectProperty: No property reflected for Swift.WritableKeyPath<App.Acronym, Swift.Optional<Swift.Int>>] [/Users/vinamelody/Code/vapor/tilapp/.build/checkouts/fluent.git-6251908308727715749/Sources/Fluent/Migration/Migration.swift:28:124]
Program ended with exit code: 1

```

Code [here](https://github.com/vinamelody/tilapp)

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 28, 2018, 2:01pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/32 "2018-03-28T14:01:13Z")

</div>

@vinamelody so you’ve hit a couple of issues there! The first is that the table name logic was changed in a recent RC, which unhelpfully meant that existing tables didn’t match up…

The current issue you’re seeing is to do with the new reflection stuff that went in last night. Unfortunately it seems to have broken models that are classes 😠

There isn’t much you can do at the moment apart from wait until it has been fixed. It’s all to do with how the layout of a class looks in memory and the fact that computed properties don’t have offsets, which has broken it… I’ll post on here when it has fixed.

One final solution you have is to replace your `Package.resolved` with the following:

```json
{
  "object": {
    "pins": [
      {
        "package": "Auth",
        "repositoryURL": "https://github.com/vapor/auth.git",
        "state": {
          "branch": null,
          "revision": "af15d9b23a421d76754535447b8cb791d9ce5fc6",
          "version": "2.0.0-rc.3"
        }
      },
      {
        "package": "Console",
        "repositoryURL": "https://github.com/vapor/console.git",
        "state": {
          "branch": null,
          "revision": "9b219b46ce0248924ed014c23bf8d4df05f2ad80",
          "version": "3.0.0-rc.2.0.1"
        }
      },
      {
        "package": "Core",
        "repositoryURL": "https://github.com/vapor/core.git",
        "state": {
          "branch": null,
          "revision": "92cef8935fbeb16516b3c687ca3039fa5ce60860",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "Crypto",
        "repositoryURL": "https://github.com/vapor/crypto.git",
        "state": {
          "branch": null,
          "revision": "5ea23edc6d3122655daf71756bc769c987a20b29",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "DatabaseKit",
        "repositoryURL": "https://github.com/vapor/database-kit.git",
        "state": {
          "branch": null,
          "revision": "965d4c8ce376819456e0bc1a6c8f388b4d6555cd",
          "version": "1.0.0-rc.2"
        }
      },
      {
        "package": "Engine",
        "repositoryURL": "https://github.com/vapor/engine.git",
        "state": {
          "branch": null,
          "revision": "6a7ca70b6858a0ac8a5c48359c80a3c37f46b47e",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "Fluent",
        "repositoryURL": "https://github.com/vapor/fluent.git",
        "state": {
          "branch": null,
          "revision": "9e684c00fc2bd1fd1adaaad5f6ae29beac7b0364",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "FluentMySQL",
        "repositoryURL": "https://github.com/vapor/fluent-mysql.git",
        "state": {
          "branch": null,
          "revision": "e941ebbb989a22a9dd15360681d7a511354d4ee7",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "Leaf",
        "repositoryURL": "https://github.com/vapor/leaf.git",
        "state": {
          "branch": null,
          "revision": "e0c8bb646556aefdaed907e48a8435655c59bab3",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "MySQL",
        "repositoryURL": "https://github.com/vapor/mysql.git",
        "state": {
          "branch": null,
          "revision": "4057d62f5576e305b6ff4b99fc3dd2eca24497a7",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "Routing",
        "repositoryURL": "https://github.com/vapor/routing.git",
        "state": {
          "branch": null,
          "revision": "2fc1d4de22a54848b35ad17b3e7f7816f19ebf90",
          "version": "3.0.0-rc.2"
        }
      },
      {
        "package": "Service",
        "repositoryURL": "https://github.com/vapor/service.git",
        "state": {
          "branch": null,
          "revision": "8ade63fc255a184ec16a1c66562b837f2b5db83f",
          "version": "1.0.0-rc.2"
        }
      },
      {
        "package": "swift-nio",
        "repositoryURL": "https://github.com/apple/swift-nio.git",
        "state": {
          "branch": null,
          "revision": "320561f4371d32c74a12158d2e18f220703fe32c",
          "version": "1.2.1"
        }
      },
      {
        "package": "swift-nio-ssl",
        "repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
        "state": {
          "branch": null,
          "revision": "85a55f91bf80afa96889426962f0e0369fae9187",
          "version": "1.0.0"
        }
      },
      {
        "package": "swift-nio-ssl-support",
        "repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
        "state": {
          "branch": null,
          "revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
          "version": "1.0.0"
        }
      },
      {
        "package": "swift-nio-zlib-support",
        "repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
        "state": {
          "branch": null,
          "revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
          "version": "1.0.0"
        }
      },
      {
        "package": "TemplateKit",
        "repositoryURL": "https://github.com/vapor/template-kit.git",
        "state": {
          "branch": null,
          "revision": "ef940383716d05ac6e1b0dcb0ba672c7c0f8a718",
          "version": "1.0.0-rc.2.0.1"
        }
      },
      {
        "package": "Validation",
        "repositoryURL": "https://github.com/vapor/validation.git",
        "state": {
          "branch": null,
          "revision": "361140562d87385df49fdb36e96841c0a92d59ae",
          "version": "2.0.0-rc.2"
        }
      },
      {
        "package": "Vapor",
        "repositoryURL": "https://github.com/vapor/vapor.git",
        "state": {
          "branch": null,
          "revision": "5f757a9a47c494af030d1ab7f82911e140682f9d",
          "version": "3.0.0-rc.2"
        }
      }
    ]
  },
  "version": 1
}

```

Then run `rm -rf .build TIL.xcodeproj`. That will remove everything and give you a working version set (I think). If you run `vapor xcode -y` that should use that file so you can keep going until the issue gets fixed.

---

<div class="post-metadata">

**Author:** ![vinamelody](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vinamelody/32/97385_2.png) [@vinamelody](https://forums.kodeco.com/u/vinamelody)\
**Post date:** [March 28, 2018, 3:13pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/33 "2018-03-28T15:13:22Z")

</div>

Hmm, still having the same error … you can inspect my code here [GitHub - vinamelody/tilapp: Vapor server side](https://github.com/vinamelody/tilapp) … oh my perhaps I’ll just wait for the fix ☹

 ![47%20PM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/e/f/ef17a53f546c2c6aec5b0de6f778ceaafeb9eddc.png)

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 28, 2018, 6:45pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/34 "2018-03-28T18:45:19Z")

</div>

I think it’s now fixed - try running `vapor update` and it should work again

---

<div class="post-metadata">

**Author:** ![vinamelody](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vinamelody/32/97385_2.png) [@vinamelody](https://forums.kodeco.com/u/vinamelody)\
**Post date:** [March 29, 2018, 12:26pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/35 "2018-03-29T12:26:28Z")

</div>

Did `vapor update` and getting another kind of error here…

 ![14%20PM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/c/b/cbc06f3e8aa58fb43dacd2f7493c1e6b51fb9759.png)

**Update:** Fixed by doing `rm -rf .build tilapp.xcodeproj` and `vapor xcode -y` again … oh boy feels like it is so dangerous to do `vapor update` at any point of time, esp in between development. I’m not sure about the assertion failed that just happened.

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 29, 2018, 4:28pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/36 "2018-03-29T16:28:08Z")

</div>

Ah good old RCs - there’s been a couple of frustrating changes the last couple of days before the release hits. However when in doubt do a clean and try a build again. `vapor update` should regenerate the project for you but sometimes Xcode is a bit keen on the caching…

---

<div class="post-metadata">

**Author:** ![vinamelody](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vinamelody/32/97385_2.png) [@vinamelody](https://forums.kodeco.com/u/vinamelody)\
**Post date:** [March 30, 2018, 3:00pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/37 "2018-03-30T15:00:06Z")

</div>

That assertion failed appeared again when I’m about to test User Password feature. That is, by removing mysql docker, create new one and run the project again. Therefore, I came back here and did another `vapor update`

uhh different Build error this time …

 ![18%20PM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/9/4/94b4f750e48b5eb908ba8f38b40e49cfd6e95d6b.png)

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 30, 2018, 3:34pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/38 "2018-03-30T15:34:46Z")

</div>

😠 more breaking changes as the releases roll out. Core 3.0.0 moved `DirectoryConfig` to another module, so you can either edit LeafProvider.swift directory and add an `import Core` to the top, or point your Leaf dependency to the `DirectoryConfigFix`. I’ve got a PR here to fix it [Directory config fix by 0xTim · Pull Request #100 · vapor/leaf · GitHub](https://github.com/vapor/leaf/pull/100)

---

<div class="post-metadata">

**Author:** ![vinamelody](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vinamelody/32/97385_2.png) [@vinamelody](https://forums.kodeco.com/u/vinamelody)\
**Post date:** [March 30, 2018, 3:38pm UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/39 "2018-03-30T15:38:17Z")

</div>

hmm alright will wait until your PR is approved 👍

---

<div class="post-metadata">

**Author:** ![0xtim](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/0xtim/32/111111_2.png) [@0xtim](https://forums.kodeco.com/u/0xtim)\
**Post date:** [March 31, 2018, 12:12am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/40 "2018-03-31T00:12:36Z")

</div>

@vinamelody the PR has just been merged, run `vapor update` and the problem should be fixed

---

<div class="post-metadata">

**Author:** ![vinamelody](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vinamelody/32/97385_2.png) [@vinamelody](https://forums.kodeco.com/u/vinamelody)\
**Post date:** [March 31, 2018, 1:43am UTC](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081/41 "2018-03-31T01:43:48Z")

</div>

For some reason, the assertion failed still occur. I stopped it and re-run again and it’s starting properly.

 ![43%20AM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/6/b/6b5a5398593c7fb1b22d615bf796b77e69a0f3c1.png)

[Previous page](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081.md?page=1)

[Next page](https://forums.kodeco.com/t/server-side-swift-with-vapor-part-22-challenge-ray-wenderlich/40081.md?page=3)
