Releases: vapor/fluent-kit
Add UInt8-backed enum test
Adds a test to ensure models with UInt8-backed enum properties work properly.
Don't eager load on empty result set
Fluent's QueryBuilder no longer attempts to run eager loads if all() returns zero models. This fixes an issue where attempting to eager load children on a query that returned zero models would result in a syntax error (#117).
Duplicate constraint name fix
FluentKit 1.0.0 Beta 2.4
- Fix array test to store json array as
.array(of: .json)(#111)
FluentKit 1.0.0 Beta 2.3
FluentKit 1.0.0 Beta 2.2
FluentKit 1.0.0 Beta 2.1
- Fixes an operator precedence issue when querying on soft-deletable models. (#104)
FluentKit 1.0.0 Beta 2
- Replaced Model lifecycle hooks with
ModelMiddleware(#93)
The use of a middleware pattern for interacting with model lifecycle allows for greater control and flexibility. This also solves the longstanding issue of accessing shared state inside of lifecycle events. Now share state can be stored on the model middleware during app configuration.
Middleware also have the ability to change an event as it is passed through the middleware chain. For example, a middleware can intercept an update event and change it to a delete.
Multiple middleware can be configured to a single database. Additionally, AnyModelMiddleware can be used to create middleware for all Fluent models passing through a given DB.
Example:
// beta.1
final class User: Model {
...
func didCreate(on db: Database) -> EventLoopFuture<Void> {
print("user created")
}
}
// beta.2
struct UserMiddleware: ModelMiddleware {
func create(model: User, on db: Database, next: AnyModelResponder) -> EventLoopFuture<Void> {
return next.create(model, on: db).map {
print("user created")
}
}
}-
Added foreign key support. (#83)
-
Publicized settable
ID.existsfor marking a model as already existing in the DB without fetching. (#94) -
Fixed an issue when two children pointed to the same parent model. (#95)
-
Fixed an issue when
createon an empty array of models (#97) -
Enabled test discovery on Linux (#102)
FluentKit 1.0.0 Beta 1
- Added a new
@OptionalParentrelation where the child's parent ID is optional. (#78) filteroperators now support comparing two columns. (#79)- Added a new protocol
ModelAliasfor 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)")
}Databasecan now specify anEventLoopPreferenceandLogger. (#84)
This is in line with changes to how Vapor 4.0.0 Beta 1 handles services.
FluentKit 1.0.0 Alpha 3.1
- Fixes a bug causing
@Parent.queryand@Parent.getto filter on the wrong column. (#68)
Notes: Previously these methods would attempt to filter the related parent by the child's key. They now filter on the parent's key (identifier).