FluentKit 1.0.0 Beta 1
Pre-release
Pre-release
- Added a new
@OptionalParent
relation where the child's parent ID is optional. (#78) filter
operators now support comparing two columns. (#79)- Added a new protocol
ModelAlias
for handling queries that join a given table more than once. (#75)
final class Match: Model {
...
@Parent(key: "home_team_id")
var homeTeam: Team
@Parent(key: "away_team_id")
var awayTeam: Team
}
final class Team: Model {
...
@Children(from: \.$homeTeam)
var homeMatches: [Match]
@Children(from: \.$awayTeam)
var awayMatches: [Match]
}
struct HomeTeam: ModelAlias {
typealias Model = Team
static var alias: String { "home_teams" }
}
struct AwayTeam: ModelAlias {
typealias Model = Team
static var alias: String { "away_teams" }
}
let matches = try Match.query(on: self.database)
.join(HomeTeam.self, on: \Match.$homeTeam == \Team.$id)
.join(AwayTeam.self, on: \Match.$awayTeam == \Team.$id)
.filter(HomeTeam.self, \Team.$name == "a")
.all().wait()
for match in matches {
let home = try match.joined(HomeTeam.self)
let away = try match.joined(AwayTeam.self)
print(match.name)
print("home: \(home.name)")
print("away: \(away.name)")
}
Database
can now specify anEventLoopPreference
andLogger
. (#84)
This is in line with changes to how Vapor 4.0.0 Beta 1 handles services.