Skip to content

FluentKit 1.0.0 Beta 1

Pre-release
Pre-release
Compare
Choose a tag to compare
@tanner0101 tanner0101 released this 24 Oct 21:34
2907bfd
  • 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 an EventLoopPreference and Logger. (#84)

This is in line with changes to how Vapor 4.0.0 Beta 1 handles services.

  • SchemaBuilder.update is now implemented.
  • Fixed an issue where @Children would serialize as an empty container if not eager loaded. (#70)
  • Fixed an issue preventing the sort method from called with a field key path. (#64)
  • Added support for accessing the cached model ID from @Children relations. (#71)