From 5ea914ce0abceeaf5e2a7459afd66f10a33dd897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 3 Feb 2019 08:42:37 +0100 Subject: [PATCH] YAGNI: JoinCondition.sqlExpression is not optional --- GRDB/QueryInterface/Association/Association.swift | 4 +--- GRDB/QueryInterface/SQLSelectQuery.swift | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/GRDB/QueryInterface/Association/Association.swift b/GRDB/QueryInterface/Association/Association.swift index 0d3781238..f9666c953 100644 --- a/GRDB/QueryInterface/Association/Association.swift +++ b/GRDB/QueryInterface/Association/Association.swift @@ -360,9 +360,7 @@ extension Association where OriginRowDecoder: MutablePersistableRecord { .filter { db in // Build a join condition: `association.recordId = record.id` // We still need to replace `record.id` with the actual record id. - guard let joinExpression = try self._impl.joinCondition.sqlExpression(db, leftAlias: recordAlias, rightAlias: associationAlias) else { - fatalError("Can't request from record without join condition") - } + let joinExpression = try self._impl.joinCondition.sqlExpression(db, leftAlias: recordAlias, rightAlias: associationAlias) // Serialize record: ["id": 123, ...] // We do it as late as possible, when request is about to be diff --git a/GRDB/QueryInterface/SQLSelectQuery.swift b/GRDB/QueryInterface/SQLSelectQuery.swift index 21e15f808..94304673b 100644 --- a/GRDB/QueryInterface/SQLSelectQuery.swift +++ b/GRDB/QueryInterface/SQLSelectQuery.swift @@ -1,4 +1,4 @@ -/// The SQLSelectQuery generates SQL for query interface requests. +/// SQLSelectQuery generates SQL for query interface requests. struct SQLSelectQuery { var relation: SQLRelation var isDistinct: Bool @@ -424,7 +424,7 @@ public /* TODO: internal */ struct JoinCondition: Equatable { /// - parameter rightAlias: A TableAlias for the table on the right of the /// JOIN operator. /// - Returns: An SQL expression. - func sqlExpression(_ db: Database, leftAlias: TableAlias, rightAlias: TableAlias) throws -> SQLExpression? { + func sqlExpression(_ db: Database, leftAlias: TableAlias, rightAlias: TableAlias) throws -> SQLExpression { let foreignKeyMapping = try foreignKeyRequest.fetch(db).mapping let columnMapping: [(left: Column, right: Column)] if originIsLeft {