diff --git a/server/connectors/deploy-connector-postgres/src/main/scala/com/prisma/deploy/connector/postgres/database/PostgresJdbcDeployDatabaseMutationBuilder.scala b/server/connectors/deploy-connector-postgres/src/main/scala/com/prisma/deploy/connector/postgres/database/PostgresJdbcDeployDatabaseMutationBuilder.scala index b14804b555..ac9938f1b6 100644 --- a/server/connectors/deploy-connector-postgres/src/main/scala/com/prisma/deploy/connector/postgres/database/PostgresJdbcDeployDatabaseMutationBuilder.scala +++ b/server/connectors/deploy-connector-postgres/src/main/scala/com/prisma/deploy/connector/postgres/database/PostgresJdbcDeployDatabaseMutationBuilder.scala @@ -109,7 +109,7 @@ case class PostgresJdbcDeployDatabaseMutationBuilder( #$aColSql, #$bColSql, FOREIGN KEY ("#$modelAColumn") REFERENCES #${qualify(project.dbName, modelA.dbName)} (#${qualify(modelA.dbNameOfIdField_!)}) ON DELETE CASCADE, - FOREIGN KEY ("#$modelBColumn") REFERENCES #${qualify(project.dbName, modelB.dbName)} (#${qualify(modelA.dbNameOfIdField_!)}) ON DELETE CASCADE + FOREIGN KEY ("#$modelBColumn") REFERENCES #${qualify(project.dbName, modelB.dbName)} (#${qualify(modelB.dbNameOfIdField_!)}) ON DELETE CASCADE );""" val modernTableCreate = sqlu""" @@ -117,7 +117,7 @@ case class PostgresJdbcDeployDatabaseMutationBuilder( #$aColSql, #$bColSql, FOREIGN KEY ("#$modelAColumn") REFERENCES #${qualify(project.dbName, modelA.dbName)} (#${qualify(modelA.dbNameOfIdField_!)}) ON DELETE CASCADE, - FOREIGN KEY ("#$modelBColumn") REFERENCES #${qualify(project.dbName, modelB.dbName)} (#${qualify(modelA.dbNameOfIdField_!)}) ON DELETE CASCADE + FOREIGN KEY ("#$modelBColumn") REFERENCES #${qualify(project.dbName, modelB.dbName)} (#${qualify(modelB.dbNameOfIdField_!)}) ON DELETE CASCADE );""" val tableCreate = relation.manifestation match { diff --git a/server/connectors/deploy-connector-sqlite/src/main/scala/com/prisma/deploy/connector/sqlite/database/SQLiteJdbcDeployDatabaseMutationBuilder.scala b/server/connectors/deploy-connector-sqlite/src/main/scala/com/prisma/deploy/connector/sqlite/database/SQLiteJdbcDeployDatabaseMutationBuilder.scala index 29dab36016..c121cd32b9 100644 --- a/server/connectors/deploy-connector-sqlite/src/main/scala/com/prisma/deploy/connector/sqlite/database/SQLiteJdbcDeployDatabaseMutationBuilder.scala +++ b/server/connectors/deploy-connector-sqlite/src/main/scala/com/prisma/deploy/connector/sqlite/database/SQLiteJdbcDeployDatabaseMutationBuilder.scala @@ -110,7 +110,7 @@ case class SQLiteJdbcDeployDatabaseMutationBuilder( #$bColSql, PRIMARY KEY ("id"), FOREIGN KEY (#$modelAColumn) REFERENCES #${qualify(modelA.dbName)} (#${qualify(modelA.dbNameOfIdField_!)}) ON DELETE CASCADE, - FOREIGN KEY (#$modelBColumn) REFERENCES #${qualify(modelB.dbName)} (#${qualify(modelA.dbNameOfIdField_!)}) ON DELETE CASCADE + FOREIGN KEY (#$modelBColumn) REFERENCES #${qualify(modelB.dbName)} (#${qualify(modelB.dbNameOfIdField_!)}) ON DELETE CASCADE );""" val modernTableCreate = sqlu""" @@ -118,7 +118,7 @@ case class SQLiteJdbcDeployDatabaseMutationBuilder( #$aColSql, #$bColSql, FOREIGN KEY (#$modelAColumn) REFERENCES #${qualify(modelA.dbName)} (#${qualify(modelA.dbNameOfIdField_!)}) ON DELETE CASCADE, - FOREIGN KEY (#$modelBColumn) REFERENCES #${qualify(modelB.dbName)} (#${qualify(modelA.dbNameOfIdField_!)}) ON DELETE CASCADE + FOREIGN KEY (#$modelBColumn) REFERENCES #${qualify(modelB.dbName)} (#${qualify(modelB.dbNameOfIdField_!)}) ON DELETE CASCADE );""" val tableCreate = relation.manifestation match { diff --git a/server/integration-tests/integration-tests-mysql/src/test/scala/com/prisma/integration/DeployingCustomIdNamesSpec.scala b/server/integration-tests/integration-tests-mysql/src/test/scala/com/prisma/integration/DeployingCustomIdNamesSpec.scala new file mode 100644 index 0000000000..8b7622f786 --- /dev/null +++ b/server/integration-tests/integration-tests-mysql/src/test/scala/com/prisma/integration/DeployingCustomIdNamesSpec.scala @@ -0,0 +1,65 @@ +package com.prisma.integration + +import org.scalatest.{FlatSpec, Matchers} + +class DeployingCustomIdNamesSpec extends FlatSpec with Matchers with IntegrationBaseSpec { + + "Using Custom Id field names with relations" should "work" in { + + val schema = + """type Person { + | id: ID! @id + | age: Int! @unique + |}""" + + val (project, _) = setupProject(schema) + + val schema1 = + """type Game { + | gameId: ID! @id + | createdAt: DateTime! @createdAt + | updatedAt: DateTime! @updatedAt + | lastUpdatedOn: String! + | players: [Player!]! @relation(link: TABLE, name: "GamePlayer") + |} + | + |type Player { + | playerId: ID! @id + | createdAt: DateTime! @createdAt + | updatedAt: DateTime! @updatedAt + | lastUpdatedOn: String! + | games: [Game!]! @relation(name: "GamePlayer") + |}""" + + deployServer.deploySchemaThatMustSucceed(project, schema1, 3, true) + } + + "Using [typename]id as a field for relations" should "work" in { + + val schema = + """type Person { + | id: ID! @id + | age: Int! @unique + |}""" + + val (project, _) = setupProject(schema) + + val schema1 = + """type Contact @db(name: "contact") { + |id: Int! @id + |info: String! + |type: String! + |customerid: Customer + |} + | + |type Customer @db(name: "customer") { + |id: Int! @id + |contact: [Contact] + |firstname: String! + |lastname: String! + |}""" + + deployServer.deploySchemaThatMustSucceed(project, schema1, 3, true) + } + +}