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.
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?
points_id
is a column on the OrderPoint
table.
Whatâs the relationship between between points and orders?
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.
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!
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()
}
@gonzalo have you got import Fluent
in the file?
Good grief. That was it. Thank you!
Interesting enough, I didnât need to import Fluent
to use sort
but I one needs to in order to use filter
Itâs the filter operators that arenât automatically imported (like ==
to compare a column and value)
Thank you for the reply