Group Group Group Group Group Group Group Group Group

Relation not loaded: Parent<Acronym, User>(key: userID)

Hello, I’m getting this error when trying to do the /api/acronyms//user call in Chapter 9. I’ve checked my code against the final code in the tutorial materials and it looks the same.

I’m able to post a new acronym with a new userID, but I can’t get the user by providing the UUID from that acronym in the above call and get the error instead.

I did the docker command line actions as noted, added the necessary properties and methods, and built and ran the project.

Any suggestions?

@tsidenfaden can you show your code? That error means you’re doing something like acronym.user rather than acronym.$user

This is my getUserHandler:

  // 1
    func getUserHandler(_ req: Request)
      throws -> EventLoopFuture<User> {
      // 2
      Acronym.find(req.parameters.get("acronymID"), on: req.db)
        .unwrap(or: Abort(.notFound))
        .flatMap { acronym in
          // 3
          acronym.$user.get(on: req.db)

and this is my updateHandler:

func updateHandler(_ req: Request) throws
        -> EventLoopFuture<Acronym> {
      let updateData =
        try req.content.decode(CreateAcronymData.self)
      return Acronym
        .find(req.parameters.get("acronymID"), on: req.db)
        .unwrap(or: Abort(.notFound))
        .flatMap { acronym in
          acronym.short = updateData.short
          acronym.long = updateData.long
          acronym.$ = updateData.userID
          return req.db).map {

That looks fine - which line does it throw on?

Good morning, the same thing happened to me, it was simply because when performing the migration, all the data in the two tables (acronyms and user) were deleted.

Seeding data again, sending a POST to user (BODY: user, username), then sending a POST to Acronyms (BODY: short, long, userID: User ID)