mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Upgrade tests with belongsTo
This commit is contained in:
1 parent
f8c99f96bc
commit
913168df2d
28 files changed
+114
-116
No files matched your search
@@ -51,13 +51,13 @@ class AssociationAggregateTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "player") { t in
|
||||
t.primaryKey("id", .integer)
|
||||
t.column("teamId", .integer).references("team")
|
||||
t.belongsTo("team")
|
||||
t.column("name", .text)
|
||||
t.column("score", .integer)
|
||||
}
|
||||
try db.create(table: "award") { t in
|
||||
t.primaryKey("customPrimaryKey", .integer)
|
||||
t.column("teamId", .integer).references("team")
|
||||
t.belongsTo("team")
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class AssociationBelongsToDecodableRecordTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "players") { t in
|
||||
t.primaryKey("id", .integer)
|
||||
t.column("teamId", .integer).references("teams")
|
||||
t.belongsTo("team")
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class AssociationBelongsToFetchableRecordTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "players") { t in
|
||||
t.primaryKey("id", .integer)
|
||||
t.column("teamId", .integer).references("teams")
|
||||
t.belongsTo("team")
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class AssociationBelongsToRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "players") { t in
|
||||
t.primaryKey("id", .integer)
|
||||
t.column("teamId", .integer).references("teams")
|
||||
t.belongsTo("team")
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase {
|
||||
t.column("name", .text)
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.column("parentId", .integer).references("parents")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,8 +546,8 @@ class AssociationBelongsToSQLTests: GRDBTestCase {
|
||||
t.column("name", .text)
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.column("parent1Id", .integer).references("parents")
|
||||
t.column("parent2Id", .integer).references("parents")
|
||||
t.belongsTo("parent1", inTable: "parents")
|
||||
t.belongsTo("parent2", inTable: "parents")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1742,7 +1742,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId", .integer).references("a")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
struct A: TableRecord { }
|
||||
struct B: TableRecord { }
|
||||
@@ -1771,7 +1771,7 @@ class AssociationBelongsToSQLTests: GRDBTestCase {
|
||||
t.column("name", .text)
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.column("parentId", .integer).references("parents")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class AssociationHasManyOrderingTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "player") { t in
|
||||
t.primaryKey("id", .integer)
|
||||
t.column("teamId", .integer).notNull().references("team")
|
||||
t.belongsTo("team").notNull()
|
||||
t.column("name", .text).notNull()
|
||||
t.column("position", .integer).notNull()
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class AssociationHasManyRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "child") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId", .integer).references("parent")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO parent (id) VALUES (1);
|
||||
@@ -49,7 +49,7 @@ class AssociationHasManyRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId", .integer).references("parents")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO parents (id) VALUES (1);
|
||||
@@ -79,7 +79,7 @@ class AssociationHasManyRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "child") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId", .integer).references("parent")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO parent (id) VALUES (1);
|
||||
|
||||
@@ -217,7 +217,7 @@ class AssociationHasManySQLTests: GRDBTestCase {
|
||||
t.primaryKey("id", .integer)
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.column("parentId", .integer).references("parents")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,8 +346,8 @@ class AssociationHasManySQLTests: GRDBTestCase {
|
||||
t.primaryKey("id", .integer)
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.column("parent1Id", .integer).references("parents")
|
||||
t.column("parent2Id", .integer).references("parents")
|
||||
t.belongsTo("parent1", inTable: "parents")
|
||||
t.belongsTo("parent2", inTable: "parents")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1074,10 +1074,10 @@ class AssociationHasManySQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "child") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId", .integer).references("parent")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
try db.create(table: "toy") { t in
|
||||
t.column("childId", .integer).references("child")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ class AssociationHasManyThroughOrderingTests: GRDBTestCase {
|
||||
t.column("name", .text).notNull()
|
||||
}
|
||||
try db.create(table: "playerRole") { t in
|
||||
t.column("teamId", .integer).notNull().references("team")
|
||||
t.column("playerId", .integer).notNull().references("player")
|
||||
t.belongsTo("team").notNull()
|
||||
t.belongsTo("player").notNull()
|
||||
t.column("position", .integer).notNull()
|
||||
t.primaryKey(["teamId", "playerId"])
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ class AssociationHasManyThroughRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "parent") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("childId").references("child")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
try db.create(table: "grandChild") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("childId").references("child")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO child (id) VALUES (1);
|
||||
@@ -64,11 +64,11 @@ class AssociationHasManyThroughRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "parents") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("childId").references("children")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
try db.create(table: "grandChildren") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("childId").references("children")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO children (id) VALUES (1);
|
||||
@@ -106,11 +106,11 @@ class AssociationHasManyThroughRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "parents") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("childId").references("children")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
try db.create(table: "grandChildren") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("childId").references("children")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO children (id) VALUES (1);
|
||||
@@ -157,8 +157,8 @@ class AssociationHasManyThroughRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "child") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId").references("parent")
|
||||
t.column("grandChildId").references("grandChild")
|
||||
t.belongsTo("parent")
|
||||
t.belongsTo("grandChild")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO parent (id) VALUES (1);
|
||||
@@ -198,8 +198,8 @@ class AssociationHasManyThroughRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId").references("parents")
|
||||
t.column("grandChildId").references("grandChildren")
|
||||
t.belongsTo("parent")
|
||||
t.belongsTo("grandChild")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO parents (id) VALUES (1);
|
||||
@@ -237,8 +237,8 @@ class AssociationHasManyThroughRowScopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "child") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId").references("parent")
|
||||
t.column("grandChildId").references("grandChild")
|
||||
t.belongsTo("parent")
|
||||
t.belongsTo("grandChild")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO parent (id) VALUES (1);
|
||||
|
||||
@@ -26,11 +26,11 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasManyWithTwoSteps(
|
||||
@@ -66,11 +66,11 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasManyWithTwoSteps(
|
||||
@@ -109,8 +109,8 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("c")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
|
||||
try testHasManyWithTwoSteps(
|
||||
@@ -146,11 +146,11 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasManyWithTwoSteps(
|
||||
@@ -334,13 +334,13 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "child") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId", .integer).references("parent")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
try db.create(table: "toy") { t in
|
||||
t.column("childId", .integer).references("child")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
try db.create(table: "pet") { t in
|
||||
t.column("childId", .integer).references("child")
|
||||
t.belongsTo("child")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,15 +462,15 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
try db.create(table: "d") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
|
||||
try testHasManyWithThreeSteps(
|
||||
@@ -521,15 +521,15 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
try db.create(table: "d") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasManyWithThreeSteps(
|
||||
@@ -581,12 +581,12 @@ class AssociationHasManyThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.column("dId").references("d")
|
||||
t.belongsTo("b")
|
||||
t.belongsTo("d")
|
||||
}
|
||||
|
||||
try testHasManyWithThreeSteps(
|
||||
|
||||
@@ -189,7 +189,7 @@ class AssociationHasOneSQLTests: GRDBTestCase {
|
||||
t.primaryKey("id", .integer)
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.column("parentId", .integer).references("parents")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,8 +299,8 @@ class AssociationHasOneSQLTests: GRDBTestCase {
|
||||
t.primaryKey("id", .integer)
|
||||
}
|
||||
try db.create(table: "children") { t in
|
||||
t.column("parent1Id", .integer).references("parents")
|
||||
t.column("parent2Id", .integer).references("parents")
|
||||
t.belongsTo("parent1", inTable: "parents")
|
||||
t.belongsTo("parent2", inTable: "parents")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,12 +49,12 @@ class AssociationHasOneThroughDecodableRecordTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
t.column("name", .text)
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
|
||||
@@ -86,12 +86,12 @@ class AssociationHasOneThroughFetchableRecordTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
t.column("name", .text)
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
|
||||
@@ -35,12 +35,12 @@ class AssociationHasOneThroughRowscopeTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
t.column("name", .text)
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
t.column("name", .text)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,11 @@ class AssociationHasOneThroughSQLDerivationTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasOneWithTwoSteps(
|
||||
@@ -68,11 +68,11 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasOneWithTwoSteps(
|
||||
@@ -111,8 +111,8 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("c")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
|
||||
try testHasOneWithTwoSteps(
|
||||
@@ -148,11 +148,11 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasOneWithTwoSteps(
|
||||
@@ -437,15 +437,15 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("dId").references("d")
|
||||
t.belongsTo("d")
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasOneWithThreeSteps(
|
||||
@@ -494,15 +494,15 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "d") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasOneWithThreeSteps(
|
||||
@@ -554,12 +554,12 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.column("dId").references("d")
|
||||
t.belongsTo("b")
|
||||
t.belongsTo("d")
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasOneWithThreeSteps(
|
||||
@@ -608,15 +608,15 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
try db.create(table: "d") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
try testHasOneWithThreeSteps(
|
||||
@@ -668,12 +668,12 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("dId").references("d")
|
||||
t.belongsTo("d")
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("a")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
|
||||
try testHasOneWithThreeSteps(
|
||||
@@ -725,12 +725,12 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "d") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("a")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
|
||||
try testHasOneWithThreeSteps(
|
||||
@@ -782,12 +782,12 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.column("dId").references("d")
|
||||
t.belongsTo("b")
|
||||
t.belongsTo("d")
|
||||
}
|
||||
|
||||
try testHasOneWithThreeSteps(
|
||||
@@ -836,15 +836,15 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("aId").references("a")
|
||||
t.belongsTo("a")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
try db.create(table: "d") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
|
||||
try testHasOneWithThreeSteps(
|
||||
@@ -1724,19 +1724,19 @@ class AssociationHasOneThroughSQLTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "d") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("eId").references("e")
|
||||
t.belongsTo("e")
|
||||
}
|
||||
try db.create(table: "c") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("dId").references("d")
|
||||
t.belongsTo("d")
|
||||
}
|
||||
try db.create(table: "b") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("cId").references("c")
|
||||
t.belongsTo("c")
|
||||
}
|
||||
try db.create(table: "a") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("bId").references("b")
|
||||
t.belongsTo("b")
|
||||
}
|
||||
|
||||
let associations = [
|
||||
|
||||
@@ -1350,9 +1350,7 @@ class AssociationPrefetchingCodableRecordTests: GRDBTestCase {
|
||||
try dbQueue.write { db in
|
||||
try db.create(table: "employee") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("managerId", .integer)
|
||||
.indexed()
|
||||
.references("employee", onDelete: .restrict)
|
||||
t.belongsTo("manager", inTable: "employee", onDelete: .restrict)
|
||||
t.column("name", .text)
|
||||
}
|
||||
try db.execute(sql: """
|
||||
|
||||
@@ -631,11 +631,11 @@ class CommonTableExpressionTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "player") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("teamId", .integer).references("team")
|
||||
t.belongsTo("team")
|
||||
}
|
||||
try db.create(table: "award") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("playerId", .integer).references("player")
|
||||
t.belongsTo("player")
|
||||
}
|
||||
struct Team: TableRecord { }
|
||||
struct Player: TableRecord {
|
||||
|
||||
@@ -205,7 +205,7 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "parents") { $0.column("id", .integer).primaryKey() }
|
||||
try db.create(table: "children") { $0.column("parentId", .integer).references("parents") }
|
||||
try db.create(table: "children") { $0.belongsTo("parent") }
|
||||
do {
|
||||
try db.execute(sql: "INSERT INTO children (parentId) VALUES (1)")
|
||||
} catch let error as DatabaseError {
|
||||
@@ -219,7 +219,7 @@ class DatabaseErrorTests: GRDBTestCase {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.create(table: "parents") { $0.column("id", .integer).primaryKey() }
|
||||
try db.create(table: "children") { $0.column("parentId", .integer).references("parents") }
|
||||
try db.create(table: "children") { $0.belongsTo("parent") }
|
||||
do {
|
||||
try db.execute(sql: "INSERT INTO children (parentId) VALUES (1)")
|
||||
} catch let error as NSError {
|
||||
|
||||
@@ -50,7 +50,7 @@ private var libraryMigrator: DatabaseMigrator = {
|
||||
}
|
||||
try db.create(table: "book") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("authorId", .integer).notNull().references("author")
|
||||
t.belongsTo("author").notNull()
|
||||
t.column("title", .text).notNull()
|
||||
}
|
||||
try db.create(virtualTable: "bookFts4", using: FTS4()) { t in
|
||||
|
||||
@@ -660,7 +660,7 @@ class QueryInterfaceExpressionsTests: GRDBTestCase {
|
||||
try dbQueue.write { db in
|
||||
try db.create(table: "parent") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId", .integer).references("parent")
|
||||
t.belongsTo("parent")
|
||||
}
|
||||
try db.create(table: "child") { t in
|
||||
t.column("childParentId", .integer).references("parent")
|
||||
|
||||
@@ -14,7 +14,7 @@ class QueryInterfacePromiseTests: GRDBTestCase {
|
||||
try dbWriter.write { db in
|
||||
try db.create(table: "node") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId", .integer).references("node")
|
||||
t.belongsTo("parent", inTable: "node")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ class QueryInterfaceRequestTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "book") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("authorId", .integer).references("author")
|
||||
t.belongsTo("author")
|
||||
}
|
||||
try db.execute(sql: """
|
||||
INSERT INTO author(id, name) VALUES (1, 'Arthur');
|
||||
|
||||
@@ -614,7 +614,7 @@ extension SQLLiteralTests {
|
||||
}
|
||||
try db.create(table: "player") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("teamId", .integer).references("team")
|
||||
t.belongsTo("team")
|
||||
t.column("score", .integer)
|
||||
}
|
||||
struct Player: TableRecord { }
|
||||
|
||||
@@ -382,7 +382,7 @@ class TableRecordDeleteTests: GRDBTestCase {
|
||||
|
||||
try db.create(table: "player") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("teamId", .integer).references("team")
|
||||
t.belongsTo("team")
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -457,7 +457,7 @@ class TableRecordDeleteTests: GRDBTestCase {
|
||||
|
||||
try db.create(table: "player") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("teamId", .integer).references("team")
|
||||
t.belongsTo("team")
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
@@ -674,7 +674,7 @@ class TableRecordUpdateTests: GRDBTestCase {
|
||||
|
||||
try db.create(table: "player") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("teamId", .integer).references("team")
|
||||
t.belongsTo("team")
|
||||
t.column("score", .integer)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
|
||||
}
|
||||
try db.create(table: "child") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("parentId", .integer).references("parent", onDelete: .cascade)
|
||||
t.belongsTo("parent", onDelete: .cascade)
|
||||
t.column("name", .text)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user