mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Add including(all:) test fixed by ebdfa9e52a
This commit is contained in:
1 parent
ebdfa9e52a
commit
58a36ec509
3 files changed
+37
-2
No files matched your search
@@ -765,7 +765,7 @@ class AssociationHasManySQLTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testJoinedAssociation() throws {
|
||||
func testAssociationFilteredByOtherAssociation() throws {
|
||||
struct Toy: TableRecord { }
|
||||
struct Child: TableRecord {
|
||||
static let toy = hasOne(Toy.self)
|
||||
|
||||
@@ -314,7 +314,7 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testJoinedAssociation() throws {
|
||||
func testAssociationFilteredByOtherAssociation() throws {
|
||||
struct Pet: TableRecord {
|
||||
static let child = belongsTo(Child.self)
|
||||
}
|
||||
|
||||
@@ -1537,4 +1537,39 @@ class AssociationPrefetchingSQLTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testAssociationFilteredByOtherAssociation() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.write { db in
|
||||
// Plain request
|
||||
do {
|
||||
let request = A
|
||||
.including(all: A
|
||||
.hasMany(
|
||||
D.self,
|
||||
through: A.hasMany(C.self)
|
||||
.joining(required: C.belongsTo(A.self).filter(sql: "1")),
|
||||
using: C.hasMany(D.self))
|
||||
.orderByPrimaryKey())
|
||||
.filter(sql: "1 + 1")
|
||||
.orderByPrimaryKey()
|
||||
|
||||
sqlQueries.removeAll()
|
||||
_ = try Row.fetchAll(db, request)
|
||||
|
||||
let selectQueries = sqlQueries.filter { $0.contains("SELECT") && !$0.contains("sqlite_") }
|
||||
XCTAssertEqual(selectQueries, [
|
||||
"""
|
||||
SELECT * FROM "a" WHERE 1 + 1 ORDER BY "cola1"
|
||||
""",
|
||||
"""
|
||||
SELECT "d".*, "c"."colc2" AS "grdb_colc2" \
|
||||
FROM "d" \
|
||||
JOIN "c" ON ("c"."colc1" = "d"."cold2") AND ("c"."colc2" IN (1, 2, 3)) \
|
||||
JOIN "a" ON ("a"."cola1" = "c"."colc2") AND (1) \
|
||||
ORDER BY "d"."cold1"
|
||||
"""])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user