Closed wenxini234 closed 5 years ago
Hi @wenxini234, check out this example:
struct GalaxyWithPlanet {
var id: Int
var name: String
var planet: Planet
}
func index(_ req: HTTPRequest) -> EventLoopFuture<[GalaxyWithPlanet]> {
return self.db.query(Galaxy.self).join(\Planet.galaxyID, to: \.id).alsoDecode(Planet.self).all().map { res in
return try res.map { (galaxy, planet) in
return try GalaxyPlanet(id: galaxy.requireID(), name: galaxy.name, planet: planet)
}
}
}
I want to get all the field information of the two tables, put it in data, and finally return to json, eg: