From 11c47812031f95a11f62df65119dd4d2a0ef256c Mon Sep 17 00:00:00 2001 From: MancunianSam Date: Wed, 5 Jun 2024 14:39:44 +0100 Subject: [PATCH] Use correct join I was joining Series on BodyId for reasons I can't fathom. This should be better. --- .../scala/uk/gov/nationalarchives/export/MetadataUtils.scala | 2 +- .../test/scala/uk/gov/nationalarchives/export/TestUtils.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/export/src/main/scala/uk/gov/nationalarchives/export/MetadataUtils.scala b/export/src/main/scala/uk/gov/nationalarchives/export/MetadataUtils.scala index 8ce2d9bc..73918635 100644 --- a/export/src/main/scala/uk/gov/nationalarchives/export/MetadataUtils.scala +++ b/export/src/main/scala/uk/gov/nationalarchives/export/MetadataUtils.scala @@ -73,7 +73,7 @@ class MetadataUtils(config: Config) { sql""" SELECT b."Name", "ConsignmentReference", COALESCE(s."Name", '') FROM "Consignment" c JOIN "Body" b ON b."BodyId" = c."BodyId" - LEFT JOIN "Series" s ON b."BodyId" = s."BodyId" + LEFT JOIN "Series" s ON c."SeriesId" = s."SeriesId" WHERE "ConsignmentId" = CAST(${consignmentId.toString} AS UUID) """ .query[(String, String, String)] .unique diff --git a/export/src/test/scala/uk/gov/nationalarchives/export/TestUtils.scala b/export/src/test/scala/uk/gov/nationalarchives/export/TestUtils.scala index b8edeaa6..bcccf482 100644 --- a/export/src/test/scala/uk/gov/nationalarchives/export/TestUtils.scala +++ b/export/src/test/scala/uk/gov/nationalarchives/export/TestUtils.scala @@ -235,8 +235,8 @@ class TestUtils extends AnyFlatSpec with TestContainerForAll with BeforeAndAfter _ <- sql"""INSERT INTO "Series" ("SeriesId", "BodyId", "Name", "Code") VALUES (CAST($seriesId AS UUID), CAST($bodyId AS UUID), 'Test', 'TST') """.update.run.transact( transactor ) - _ <- sql""" INSERT INTO "Consignment" ("ConsignmentId", "UserId", "Datetime", "ConsignmentSequence", "ConsignmentReference", "ConsignmentType", "BodyId") - VALUES (CAST($consignmentId AS UUID), CAST($userId AS UUID), CAST($dateTime AS TIMESTAMP), $sequence, $consignmentRef, 'standard', CAST($bodyId AS UUID)) """.update.run + _ <- sql""" INSERT INTO "Consignment" ("ConsignmentId", "UserId", "Datetime", "ConsignmentSequence", "ConsignmentReference", "ConsignmentType", "BodyId", "SeriesId") + VALUES (CAST($consignmentId AS UUID), CAST($userId AS UUID), CAST($dateTime AS TIMESTAMP), $sequence, $consignmentRef, 'standard', CAST($bodyId AS UUID), CAST($seriesId AS UUID)) """.update.run .transact(transactor) _ <- fileIds.map { fileId => sql""" INSERT INTO "File" ("FileId", "ConsignmentId", "UserId", "Datetime")