diff --git a/GRDB/QueryInterface/Association/Association.swift b/GRDB/QueryInterface/Association/Association.swift index 2c034f97b..c578b78e1 100644 --- a/GRDB/QueryInterface/Association/Association.swift +++ b/GRDB/QueryInterface/Association/Association.swift @@ -48,11 +48,9 @@ public protocol Association: DerivableRequest { /// } func forKey(_ key: String) -> Self - // TODO: this one prevents "through" associations like HasOneThrough, HasManyThrough, etc. /// :nodoc: var request: AssociationRequest { get } - // TODO: this one prevents "through" associations like HasOneThrough, HasManyThrough, etc. /// :nodoc: func joinCondition(_ db: Database) throws -> JoinCondition @@ -213,6 +211,8 @@ extension Association { } } +/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features) +/// :nodoc: public typealias JoinCondition = (_ leftAlias: TableAlias, _ rightAlias: TableAlias) -> SQLExpression? /// Turns a ForeignKeyRequest into a JoinCondition @@ -288,7 +288,8 @@ extension Association where OriginRowDecoder: MutablePersistableRecord { let associationAlias = TableAlias() let recordAlias = TableAlias() - // Turn JOIN into SELECT FROM + // Turn the association request into a query interface request: + // JOIN association -> SELECT FROM association return QueryInterfaceRequest(request) // Turn the JOIN condition into a regular WHERE condition diff --git a/GRDB/QueryInterface/Association/AssociationRequest.swift b/GRDB/QueryInterface/Association/AssociationRequest.swift index 789e1326a..3f7909a5e 100644 --- a/GRDB/QueryInterface/Association/AssociationRequest.swift +++ b/GRDB/QueryInterface/Association/AssociationRequest.swift @@ -2,6 +2,7 @@ /// /// In `SELECT a.*, b.* FROM a JOIN b ON b.aid = a.id AND b.name = 'foo'`, /// the AssociationRequest is (`b.*` + `b.name = 'foo'`). +/// :nodoc: public struct AssociationRequest { let query: AssociationQuery diff --git a/GRDB/QueryInterface/Association/BelongsToAssociation.swift b/GRDB/QueryInterface/Association/BelongsToAssociation.swift index bde6e005a..3b9fd882d 100644 --- a/GRDB/QueryInterface/Association/BelongsToAssociation.swift +++ b/GRDB/QueryInterface/Association/BelongsToAssociation.swift @@ -91,6 +91,7 @@ public struct BelongsToAssociation: Association { } } +// Allow BelongsToAssociation(...).filter(key: ...) extension BelongsToAssociation: TableRequest where Destination: TableRecord { /// :nodoc: public var databaseTableName: String { return Destination.databaseTableName } diff --git a/GRDB/QueryInterface/Association/ForeignKey.swift b/GRDB/QueryInterface/Association/ForeignKey.swift index d1e80ab2c..5b4312762 100644 --- a/GRDB/QueryInterface/Association/ForeignKey.swift +++ b/GRDB/QueryInterface/Association/ForeignKey.swift @@ -57,8 +57,8 @@ /// static let author = belongsTo(Person.self, using: authorForeignKey) /// } public struct ForeignKey { - let originColumns: [String] - let destinationColumns: [String]? + var originColumns: [String] + var destinationColumns: [String]? /// Creates a ForeignKey intended to define a record association. /// diff --git a/GRDB/QueryInterface/Association/ForeignKeyRequest.swift b/GRDB/QueryInterface/Association/ForeignKeyRequest.swift index 771e90a77..077581950 100644 --- a/GRDB/QueryInterface/Association/ForeignKeyRequest.swift +++ b/GRDB/QueryInterface/Association/ForeignKeyRequest.swift @@ -79,5 +79,4 @@ struct ForeignKeyRequest { } /// The (origin, destination) column pairs that join a left table to a right table. -/// :nodoc: typealias ForeignKeyMapping = [(origin: String, destination: String)] diff --git a/GRDB/QueryInterface/Association/HasManyAssociation.swift b/GRDB/QueryInterface/Association/HasManyAssociation.swift index 575cf8dc0..7e0fa6b72 100644 --- a/GRDB/QueryInterface/Association/HasManyAssociation.swift +++ b/GRDB/QueryInterface/Association/HasManyAssociation.swift @@ -91,6 +91,7 @@ public struct HasManyAssociation: Association { } } +// Allow HasManyAssociation(...).filter(key: ...) extension HasManyAssociation: TableRequest where Destination: TableRecord { /// :nodoc: public var databaseTableName: String { return Destination.databaseTableName } diff --git a/GRDB/QueryInterface/Association/HasOneAssociation.swift b/GRDB/QueryInterface/Association/HasOneAssociation.swift index 4df3f5f59..58bb5eea6 100644 --- a/GRDB/QueryInterface/Association/HasOneAssociation.swift +++ b/GRDB/QueryInterface/Association/HasOneAssociation.swift @@ -93,6 +93,7 @@ public struct HasOneAssociation : Association { } } +// Allow HasOneAssociation(...).filter(key: ...) extension HasOneAssociation: TableRequest where Destination: TableRecord { /// :nodoc: public var databaseTableName: String { return Destination.databaseTableName } diff --git a/GRDB/QueryInterface/Column.swift b/GRDB/QueryInterface/Column.swift index bcdc7fe86..e66ca6ba4 100644 --- a/GRDB/QueryInterface/Column.swift +++ b/GRDB/QueryInterface/Column.swift @@ -1,12 +1,11 @@ -/// Adopt the ColumnExpression protocol in order to define a custom column type. +/// Adopt the ColumnExpression protocol when you define a column type. /// /// You can, for example, define a String-based column enum: /// /// enum Columns: String, ColumnExpression { /// case id, name, score /// } -/// let nameColumn = Columns.name -/// let arthur = try Player.filter(nameColumn == "Arthur").fetchOne(db) +/// let arthur = try Player.filter(Columns.name == "Arthur").fetchOne(db) /// /// You can also define a genuine column type: ///