Chapter 7: Compilation Error on filter and group filter

In Chapter 7, in the part where it talks about using filter group to apply a search term to more than one property, I’m getting a compilation error, “Type of expression is ambiguous without more context”. I do not understand this. Everything has worked fine up to the filter examples. Here is the complete code for the route:

    router.get("api", "acronyms", "search") { req -> Future<[Acronym]> in
        guard let searchTerm = req.query[String.self, at: "term"] else {
            throw Abort(.badRequest)
        }
        return Acronym.query(on: req).group(.or) { or in
            or.filter(\.short == searchTerm)
            or.filter(\.long == searchTerm)
            }.all()
    }

A similar issue also happens with the previous single filter example. The complier appears to be complaining about the back slash.

I found the answer. I missed a little part in the setup code where we needed to import Fluent. Derp!

1 Like

@joesludge Glad you managed to sort it out. Cheers! :]