Group Group Group Group Group Group Group Group Group

Server Side Swift with Vapor - Part 14: Fluent | Ray Wenderlich


#21

It’s not a sibling (I don’t think) because one Point has many OrderPoints, but an OrderPoint only has one Point. So it’s a one to many.


#22

In that case is there any reason why you haven’t modelled it slightly differently and added the point_id as a column to the OrderPoint table?


#23

points_id is a column on the OrderPoint table.

UhAuM


#24

What’s the relationship between between points and orders?


#25

Think of ‘Points’ table as a list of things you could order. I’m using the names the client wanted so don’t blame me :] So the Points would have a ‘sweeper’ you could order at a cost of 2, or a ‘promo’ at a cost of 15. In my ‘Order’ I might want 3 sweepers and 1 promo. So my total points would end up at (3 * 2) + (1 * 15)

So there’d be 1 Order item, 2 OrderPoints linked to the order, and then each OrderPoints would each have a single Points linked to it.


#26

Sounds like you need to organise the relationships yourself! Take a look at how joins are done in the sibling code to give you some pointers!


#28

#29

Hmm - I appreciate the updates to searchHandler however the compiler is unable to resolve \.short and \.long. I get, “Type of expression is ambiguous without more context”.

func searchHandler(_ req: Request) throws -> Future<[Acronym]> {
    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()
}

#30

@gonzalo have you got import Fluent in the file?


#31

Good grief. That was it. Thank you!