From 604a51bb790793d28ea453fbb06ac637e80e361d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 17 May 2019 17:58:57 +0200 Subject: [PATCH] Cleanup --- .../QueryInterface/Association/Association.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/GRDB/QueryInterface/Association/Association.swift b/GRDB/QueryInterface/Association/Association.swift index 2f13597ed..0087ac459 100644 --- a/GRDB/QueryInterface/Association/Association.swift +++ b/GRDB/QueryInterface/Association/Association.swift @@ -70,7 +70,7 @@ extension Association { /// let team: Team = row["custom"] /// } var key: String { - return sqlAssociation.key + return sqlAssociation.destinationKey } /// Creates an association which selects *selection*. @@ -510,17 +510,21 @@ public /* TODO: internal */ struct SQLAssociation { return AssociationStep(key: key, condition: condition, relation: transform(relation)) } } - private var steps: [AssociationStep] // Never empty. Last is destination. + + // All steps, from pivot to destination. Never empty. + private var steps: [AssociationStep] + var keyPath: [String] { return steps.map { $0.key} } + private var destination: AssociationStep { get { return steps[steps.count - 1] } set { steps[steps.count - 1] = newValue } } + var destinationKey: String { return destination.key } + private var pivot: AssociationStep { get { return steps[0] } set { steps[0] = newValue } } - var key: String { return destination.key } - var keyPath: [String] { return steps.map { $0.key} } var pivotCondition: SQLAssociationCondition { return pivot.condition } @@ -547,7 +551,7 @@ public /* TODO: internal */ struct SQLAssociation { result.pivot.key = key return result } - + /// Transforms the destination relation func mapDestinationRelation(_ transform: (SQLRelation) -> SQLRelation) -> SQLAssociation { var result = self @@ -561,7 +565,7 @@ public /* TODO: internal */ struct SQLAssociation { result.pivot = result.pivot.mapRelation(transform) return result } - + /// Returns a new association func through(_ other: SQLAssociation) -> SQLAssociation { return SQLAssociation(steps: other.steps + steps)