From 5e7235307ad436c6e77c09ef3755d7fbd7100cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 30 Apr 2018 08:36:29 +0200 Subject: [PATCH] Cleanup --- .../Association/Association.swift | 4 ---- .../Association/BelongsToAssociation.swift | 18 ++++++++---------- .../Association/HasManyAssociation.swift | 18 ++++++++---------- .../Association/HasOneAssociation.swift | 18 ++++++++---------- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/GRDB/QueryInterface/Association/Association.swift b/GRDB/QueryInterface/Association/Association.swift index 29f5fb6d8..e831f1ce0 100644 --- a/GRDB/QueryInterface/Association/Association.swift +++ b/GRDB/QueryInterface/Association/Association.swift @@ -56,10 +56,6 @@ public protocol Association: SelectionRequest, FilteredRequest, OrderedRequest { func mapRequest(_ transform: (AssociationRequest) -> AssociationRequest) -> Self } -func defaultAssociationKey(for type: T.Type) -> String { - return T.databaseTableName -} - extension Association { /// Creates an association with a new net of selected columns. /// diff --git a/GRDB/QueryInterface/Association/BelongsToAssociation.swift b/GRDB/QueryInterface/Association/BelongsToAssociation.swift index 4cc4de2ad..4b66eba1d 100644 --- a/GRDB/QueryInterface/Association/BelongsToAssociation.swift +++ b/GRDB/QueryInterface/Association/BelongsToAssociation.swift @@ -11,15 +11,14 @@ public struct BelongsToAssociation : Association, TableRequest wher public var databaseTableName: String { return RightAssociated.databaseTableName } /// :nodoc: - public let request: AssociationRequest + public var request: AssociationRequest let foreignKeyRequest: ForeignKeyRequest public func forKey(_ key: String) -> BelongsToAssociation { - return BelongsToAssociation( - key: key, - request: request, - foreignKeyRequest: foreignKeyRequest) + var association = self + association.key = key + return association } /// :nodoc: @@ -31,10 +30,9 @@ public struct BelongsToAssociation : Association, TableRequest wher /// :nodoc: public func mapRequest(_ transform: (AssociationRequest) -> AssociationRequest) -> BelongsToAssociation { - return BelongsToAssociation( - key: key, - request: transform(request), - foreignKeyRequest: foreignKeyRequest) + var association = self + association.request = transform(request) + return association } } @@ -53,7 +51,7 @@ extension TableRecord { foreignKey: foreignKey) return BelongsToAssociation( - key: key ?? defaultAssociationKey(for: Right.self), + key: key ?? Right.databaseTableName, request: AssociationRequest(rightRequest), foreignKeyRequest: foreignKeyRequest) } diff --git a/GRDB/QueryInterface/Association/HasManyAssociation.swift b/GRDB/QueryInterface/Association/HasManyAssociation.swift index acc642c00..a61dca186 100644 --- a/GRDB/QueryInterface/Association/HasManyAssociation.swift +++ b/GRDB/QueryInterface/Association/HasManyAssociation.swift @@ -11,15 +11,14 @@ public struct HasManyAssociation : Association, TableRequest where public var databaseTableName: String { return RightAssociated.databaseTableName } /// :nodoc: - public let request: AssociationRequest + public var request: AssociationRequest let foreignKeyRequest: ForeignKeyRequest public func forKey(_ key: String) -> HasManyAssociation { - return HasManyAssociation( - key: key, - request: request, - foreignKeyRequest: foreignKeyRequest) + var association = self + association.key = key + return association } /// :nodoc: @@ -31,10 +30,9 @@ public struct HasManyAssociation : Association, TableRequest where /// :nodoc: public func mapRequest(_ transform: (AssociationRequest) -> AssociationRequest) -> HasManyAssociation { - return HasManyAssociation( - key: key, - request: transform(request), - foreignKeyRequest: foreignKeyRequest) + var association = self + association.request = transform(request) + return association } } @@ -53,7 +51,7 @@ extension TableRecord { foreignKey: foreignKey) return HasManyAssociation( - key: key ?? defaultAssociationKey(for: Right.self), + key: key ?? Right.databaseTableName, request: AssociationRequest(rightRequest), foreignKeyRequest: foreignKeyRequest) } diff --git a/GRDB/QueryInterface/Association/HasOneAssociation.swift b/GRDB/QueryInterface/Association/HasOneAssociation.swift index b18dacb9f..22c8dbb6f 100644 --- a/GRDB/QueryInterface/Association/HasOneAssociation.swift +++ b/GRDB/QueryInterface/Association/HasOneAssociation.swift @@ -11,15 +11,14 @@ public struct HasOneAssociation : Association, TableRequest where public var databaseTableName: String { return RightAssociated.databaseTableName } /// :nodoc: - public let request: AssociationRequest + public var request: AssociationRequest let foreignKeyRequest: ForeignKeyRequest public func forKey(_ key: String) -> HasOneAssociation { - return HasOneAssociation( - key: key, - request: request, - foreignKeyRequest: foreignKeyRequest) + var association = self + association.key = key + return association } /// :nodoc: @@ -31,10 +30,9 @@ public struct HasOneAssociation : Association, TableRequest where /// :nodoc: public func mapRequest(_ transform: (AssociationRequest) -> AssociationRequest) -> HasOneAssociation { - return HasOneAssociation( - key: key, - request: transform(request), - foreignKeyRequest: foreignKeyRequest) + var association = self + association.request = transform(request) + return association } } @@ -53,7 +51,7 @@ extension TableRecord { foreignKey: foreignKey) return HasOneAssociation( - key: key ?? defaultAssociationKey(for: Right.self), + key: key ?? Right.databaseTableName, request: AssociationRequest(rightRequest), foreignKeyRequest: foreignKeyRequest) }