From 0ad7d5e894f071789286c2e88d9a35c308c822ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 24 May 2019 13:18:00 +0200 Subject: [PATCH] Fix failing test for parallel inclusion of hasManyThrough(_, through: belongsTo, via: hasMany) --- GRDB/QueryInterface/SQL/SQLRelation.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/GRDB/QueryInterface/SQL/SQLRelation.swift b/GRDB/QueryInterface/SQL/SQLRelation.swift index dfc2c8479..9320c50c6 100644 --- a/GRDB/QueryInterface/SQL/SQLRelation.swift +++ b/GRDB/QueryInterface/SQL/SQLRelation.swift @@ -311,8 +311,13 @@ extension SQLRelation { /// as HasManyThrough, which have any number of pivot relations between the /// origin and the destination. func appending(_ association: SQLAssociation, kind: SQLRelation.Child.Kind) -> SQLRelation { - let destinationChildKey = association.destination.key.name(for: kind.cardinality) - let destinationChild = SQLRelation.Child( + let childCardinality = (kind == .allNotPrefetched) + // preserve association cardinality in intermediate steps of including(all:) + ? association.destination.cardinality + // force desired cardinality otherwize + : kind.cardinality + let childKey = association.destination.key.name(for: childCardinality) + let child = SQLRelation.Child( kind: kind, condition: association.destination.condition, relation: association.destination.relation) @@ -328,7 +333,7 @@ extension SQLRelation { // // let association = Origin.belongsTo(Destination.self) // Origin.including(required: association) - return appendingChild(destinationChild, forKey: destinationChildKey) + return appendingChild(child, forKey: childKey) } // This is an indirect join from origin to destination, through @@ -351,7 +356,7 @@ extension SQLRelation { reducedAssociation.destination.relation = reducedAssociation.destination.relation .select([]) // Intermediate steps are not prefetched - .appendingChild(destinationChild, forKey: destinationChildKey) + .appendingChild(child, forKey: childKey) switch kind { case .oneRequired, .oneOptional, .allNotPrefetched: