Skip to content

Fluent 2.0 Alpha 2

Pre-release
Pre-release
Compare
Choose a tag to compare
@loganwright loganwright released this 13 Feb 13:11

New:

  • Entities can apply custom ID Keys.

Custom ID Key

You can override the idKey for an individual entity by implement static var idKey: String on your model. Fluent will now use this id key for fetching your model, saving, etc (instead of the driver's id key).

final class MyUser: Entity {
    ...
    static var idKey = "fooid"
}

Note: Preparations still require a custom idKey to be passed.

extension MyUser {
    static func prepare(_ database: Database) throws {
        try database.create(entity) { myUsers in
            myUsers.id(idKey)
            ...
        }
    }
}