Associations: inline documentation

This commit is contained in:
Gwendal Roué committed 2018-05-21 07:53:06 +02:00
1 parent 4eac0797fa
commit 0620b1b513
8 files changed
+12 -9

No files matched your search

@@ -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<RowDecoder> { 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
@@ -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<T> {
let query: AssociationQuery
@@ -91,6 +91,7 @@ public struct BelongsToAssociation<Origin, Destination>: Association {
}
}
// Allow BelongsToAssociation(...).filter(key: ...)
extension BelongsToAssociation: TableRequest where Destination: TableRecord {
/// :nodoc:
public var databaseTableName: String { return Destination.databaseTableName }
@@ -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.
///
@@ -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)]
@@ -91,6 +91,7 @@ public struct HasManyAssociation<Origin, Destination>: Association {
}
}
// Allow HasManyAssociation(...).filter(key: ...)
extension HasManyAssociation: TableRequest where Destination: TableRecord {
/// :nodoc:
public var databaseTableName: String { return Destination.databaseTableName }
@@ -93,6 +93,7 @@ public struct HasOneAssociation<Origin, Destination> : Association {
}
}
// Allow HasOneAssociation(...).filter(key: ...)
extension HasOneAssociation: TableRequest where Destination: TableRecord {
/// :nodoc:
public var databaseTableName: String { return Destination.databaseTableName }
+2 -3
View File
@@ -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:
///