From 126b22f550d78cab0bcaad2a065175d9df106f02 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Tue, 29 Oct 2024 22:55:46 +0100 Subject: [PATCH] tests: autoformat complex sql queries for easier debugging --- composer.json | 1 + tests/inc/QueryChecker.php | 19 ++- .../EntityEmbeddableTest_testSetInvalid.sql | 1 + .../CollectionAggregationJoinTest_testAny.sql | 77 ++++++++- ...onAggregationJoinTest_testAnyDependent.sql | 123 ++++++++++++++- ...ggregationJoinTest_testCountAggregator.sql | 89 ++++++++++- ...nTest_testHasValueOrEmptyWithFunctions.sql | 72 ++++++++- ...Test_testIndependentAnyOverManyHasMany.sql | 60 ++++++- ...t_testIndependentAnyWithGroupingOverPk.sql | 67 +++++++- ...egationJoinTest_testIndependentSelects.sql | 54 ++++++- ...CollectionAggregationJoinTest_testNone.sql | 48 +++++- ...estAggregationWithNoAggregateCondition.sql | 60 ++++++- .../CollectionAggregationTest_testAvg.sql | 33 +++- ...gregationTest_testAvgOnEmptyCollection.sql | 13 +- .../CollectionAggregationTest_testCount.sql | 53 ++++++- .../CollectionAggregationTest_testMax.sql | 16 +- ...egationTest_testMaxWithEmptyCollection.sql | 13 +- .../CollectionAggregationTest_testMin.sql | 16 +- ...egationTest_testMinWithEmptyCollection.sql | 13 +- .../CollectionAggregationTest_testSum.sql | 16 +- ...nEmbeddablesTest_testInvalidExpression.sql | 1 + .../CollectionEmbeddablesTest_testOrderBy.sql | 25 ++- ...estHavingWithSameNamedColumnsInGroupBy.sql | 34 +++- ...ConditionsInDifferentJoinsAndSameTable.sql | 18 ++- ...ollectionTest_testConditionsInSameJoin.sql | 15 +- ...lectionTest_testCountOnLimitedWithJoin.sql | 44 +++++- .../CollectionTest_testDistinct.sql | 21 ++- .../CollectionTest_testJoinDifferentPath.sql | 24 ++- .../CollectionTest_testOrdering.sql | 23 ++- .../CollectionTest_testOrderingMultiple.sql | 23 ++- ...nTest_testOrderingWithOptionalProperty.sql | 47 +++++- ...ropertyFunctionTest_testManyHasOneJoin.sql | 1 + ...ropertyFunctionTest_testOneHasManyJoin.sql | 1 + ...PropertyFunctionTest_testOneHasOneJoin.sql | 1 + ...tityCloningTest_testCloningManyHasMany.sql | 12 +- ...ntityCloningTest_testCloningOneHasMany.sql | 27 +++- ..._testGetByIdWronglyUsedWithIndexedKeys.sql | 1 + ...CompositePKTest_testSetIdOnlyPartially.sql | 1 + ...st_testSetIdWithInsufficientParameters.sql | 1 + .../ModelRefreshAllTest_testMHMRelations.sql | 24 ++- .../ModelRefreshAllTest_testMHMRelations2.sql | 24 ++- .../ModelRefreshAllTest_testTrackedMHM.sql | 24 ++- .../EntityRelationshipsTest_testBasics.sql | 27 +++- ...ationshipsTest_testDeepTraversalHasOne.sql | 12 +- ...shipsTest_testDeepTraversalManyHasMany.sql | 12 +- ...RelationshipsTest_testSetRelationships.sql | 1 + .../RelationshipCyclicTest_testCycleCheck.sql | 1 + .../RelationshipManyHasManyTest_testCache.sql | 87 +++++++++- ...elationshipManyHasManyTest_testCaching.sql | 37 ++++- ...shipManyHasManyTest_testCachingPreload.sql | 69 +++++++- ...sManyTest_testCollectionCountWithLimit.sql | 20 ++- ...t_testCountAfterRemoveAndFlushAndCount.sql | 60 ++++++- ...oredOnManyHasManyRelationshipCondition.sql | 125 ++++++++++++++- ...t_testCountStoredOnManyToManyCondition.sql | 22 ++- ...yHasManyTest_testEmptyPreloadContainer.sql | 55 ++++++- ...sManyTest_testJoinAcrossDifferentPaths.sql | 71 ++++++++- .../RelationshipManyHasManyTest_testLimit.sql | 149 +++++++++++++++++- ...lationshipManyHasManyTest_testRawValue.sql | 77 ++++++++- ...RelationshipManyHasManyTest_testRemove.sql | 27 +++- ...hipManyHasManyTest_testSelfReferencing.sql | 25 ++- ...yHasManyTest_testSymmetricRelationship.sql | 12 +- ...ipManyHasOneTest_testProperAggregation.sql | 55 ++++++- ...HasManyRemoveTest_testRemoveCollection.sql | 12 +- ...moveTest_testRemoveCollectionAndParent.sql | 12 +- ...t_testCountAfterRemoveAndFlushAndCount.sql | 12 +- ...toredOnOneHasManyRelationshipCondition.sql | 67 +++++++- ...t_testDefaultOrderingOnEmptyCollection.sql | 1 + ...leColumnOnHasManyRelationshipCondition.sql | 28 +++- ...ipOneHasManyTest_testOrderingWithJoins.sql | 11 +- ...elationshipOneHasManyTest_testRawValue.sql | 12 +- ...stSameTableJoinWithImplicitAggregation.sql | 80 +++++++++- ...ionshipOneHasOneTest_testCascadeRemove.sql | 12 +- ...lationshipOneHasOneTest_testCollection.sql | 28 +++- ...tionshipOneHasOneTest_testQueryBuilder.sql | 57 ++++++- ...hipsManyHasManyCollectionTest_testAddA.sql | 12 +- ...hipsManyHasManyCollectionTest_testAddB.sql | 24 ++- ...hipsManyHasManyCollectionTest_testAddC.sql | 24 ++- ...hipsManyHasManyCollectionTest_testAddD.sql | 24 ++- ...hipsManyHasManyCollectionTest_testAddE.sql | 24 ++- ...hipsManyHasManyCollectionTest_testAddF.sql | 12 +- ...hipsManyHasManyCollectionTest_testAddH.sql | 24 ++- ...hipsManyHasManyCollectionTest_testAddI.sql | 36 ++++- ...ectionTest_testFetchDerivedCollectionA.sql | 12 +- ...ectionTest_testFetchDerivedCollectionB.sql | 18 ++- ...sManyCollectionTest_testFetchExistingA.sql | 48 +++++- ...sManyHasManyCollectionTest_testRemoveA.sql | 24 ++- ...sManyHasManyCollectionTest_testRemoveB.sql | 12 +- ...psOneHasManyCollectionTest_testRemoveB.sql | 12 +- ...psOneHasManyCollectionTest_testRemoveC.sql | 12 +- ...anyPersistenceTest_testCollectionCount.sql | 12 +- ...stForeignKeyInNonConnectedRelationship.sql | 40 ++++- ...scadeRemoveTest_testBasicCascadeRemove.sql | 12 +- ...t_testCascadeWithOneHasOneRelationship.sql | 12 +- ...ositoryPersistenceTest_testManyHasMany.sql | 12 +- 94 files changed, 2753 insertions(+), 165 deletions(-) diff --git a/composer.json b/composer.json index 742bb2ae..2891f9c1 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "phpstan/phpdoc-parser": "2.0.x-dev" }, "require-dev": { + "doctrine/sql-formatter": "^1.5.1", "nette/bootstrap": "~3.1", "nette/di": "^3.1", "nette/neon": "~3.0", diff --git a/tests/inc/QueryChecker.php b/tests/inc/QueryChecker.php index a240524e..c95f95d8 100644 --- a/tests/inc/QueryChecker.php +++ b/tests/inc/QueryChecker.php @@ -3,6 +3,8 @@ namespace NextrasTests\Orm; +use Doctrine\SqlFormatter\NullHighlighter; +use Doctrine\SqlFormatter\SqlFormatter; use Nette\Utils\FileSystem; use Nextras\Dbal\Drivers\Exception\DriverException; use Nextras\Dbal\ILogger; @@ -18,10 +20,13 @@ class QueryChecker implements ILogger /** @var string */ private $sqls = ''; + private SqlFormatter $formatter; + public function __construct(string $name) { $this->name = str_replace('\\', '/', $name); + $this->formatter = new SqlFormatter(new NullHighlighter()); } @@ -31,12 +36,12 @@ public function assert(): void $ci = getenv('GITHUB_ACTIONS') !== false; if (!$ci) { FileSystem::createDir(dirname($file)); - FileSystem::write($file, $this->sqls); + FileSystem::write($file, trim($this->sqls) . "\n"); } else { if (!file_exists($file)) { throw new \Exception("Missing $this->name.sql file, run `composer tests` locally (with Postgres) to generate the expected SQL queries files."); } - Assert::same(FileSystem::read($file), $this->sqls); + Assert::same(FileSystem::read($file), trim($this->sqls) . "\n"); } } @@ -53,14 +58,16 @@ public function onDisconnect(): void public function onQuery(string $sqlQuery, float $timeTaken, ?Result $result): void { - if (strpos($sqlQuery, 'pg_catalog.') !== false) return; - $this->sqls .= "$sqlQuery;\n"; + if (str_contains($sqlQuery, 'pg_catalog.')) return; + $formattedSql = str_contains($sqlQuery, 'LEFT JOIN') ? $this->formatter->format($sqlQuery) . ";\n\n" : $sqlQuery . ";\n"; + $this->sqls .= $formattedSql; } public function onQueryException(string $sqlQuery, float $timeTaken, ?DriverException $exception): void { - if (strpos($sqlQuery, 'pg_catalog.') !== false) return; - $this->sqls .= "$sqlQuery;\n"; + if (str_contains($sqlQuery, 'pg_catalog.')) return; + $formattedSql = str_contains($sqlQuery, 'LEFT JOIN') ? $this->formatter->format($sqlQuery) . ";\n\n" : $sqlQuery . ";\n"; + $this->sqls .= $formattedSql; } } diff --git a/tests/sqls/NextrasTests/Orm/Entity/EntityEmbeddableTest_testSetInvalid.sql b/tests/sqls/NextrasTests/Orm/Entity/EntityEmbeddableTest_testSetInvalid.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Entity/EntityEmbeddableTest_testSetInvalid.sql +++ b/tests/sqls/NextrasTests/Orm/Entity/EntityEmbeddableTest_testSetInvalid.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testAny.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testAny.sql index 0b4694c5..71854e80 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testAny.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testAny.sql @@ -1,4 +1,73 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any" ON ("authors"."id" = "books_any"."author_id") WHERE ((("books_any"."title" = 'Book 1'))) GROUP BY "authors"."id"; -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any" ON ("authors"."id" = "books_any"."author_id") WHERE ((("books_any"."title" = 'Book 1'))) GROUP BY "authors"."id") temp; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any" ON ("authors"."id" = "books_any"."author_id") WHERE ((("books_any"."title" = 'Book 1'))) GROUP BY "authors"."id"; -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any" ON ("authors"."id" = "books_any"."author_id") WHERE ((("books_any"."title" = 'Book 1'))) GROUP BY "authors"."id") temp; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any" ON ( + "authors"."id" = "books_any"."author_id" + ) +WHERE + ( + ( + ("books_any"."title" = 'Book 1') + ) + ) +GROUP BY + "authors"."id"; + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any" ON ( + "authors"."id" = "books_any"."author_id" + ) + WHERE + ( + ( + ("books_any"."title" = 'Book 1') + ) + ) + GROUP BY + "authors"."id" + ) temp; + +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any" ON ( + "authors"."id" = "books_any"."author_id" + ) +WHERE + ( + ( + ("books_any"."title" = 'Book 1') + ) + ) +GROUP BY + "authors"."id"; + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any" ON ( + "authors"."id" = "books_any"."author_id" + ) + WHERE + ( + ( + ("books_any"."title" = 'Book 1') + ) + ) + GROUP BY + "authors"."id" + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testAnyDependent.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testAnyDependent.sql index bcac78cf..79208ad0 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testAnyDependent.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testAnyDependent.sql @@ -1,4 +1,119 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any" ON ("authors"."id" = "books_any"."author_id") LEFT JOIN "public"."authors" AS "books_translator_any" ON ("books_any"."translator_id" = "books_translator_any"."id") WHERE (("books_any"."title" = 'Book 1') AND ("books_translator_any"."id" IS NULL)) GROUP BY "authors"."id"; -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any" ON ("authors"."id" = "books_any"."author_id") LEFT JOIN "public"."authors" AS "books_translator_any" ON ("books_any"."translator_id" = "books_translator_any"."id") WHERE (("books_any"."title" = 'Book 1') AND ("books_translator_any"."id" IS NULL)) GROUP BY "authors"."id") temp; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_count" ON (("authors"."id" = "books_count"."author_id") OR (("authors"."id" = "books_count"."author_id") AND "books_count"."price" < 100)) LEFT JOIN "public"."authors" AS "books_translator_count" ON (("books_count"."translator_id" = "books_translator_count"."id") AND "books_translator_count"."id" IS NOT NULL) GROUP BY "authors"."id" HAVING ((COUNT("books_translator_count"."id") >= 1 AND COUNT("books_translator_count"."id") <= 1) OR (COUNT("books_count"."id") >= 1 AND COUNT("books_count"."id") <= 1)); -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_count" ON (("authors"."id" = "books_count"."author_id") OR (("authors"."id" = "books_count"."author_id") AND "books_count"."price" < 100)) LEFT JOIN "public"."authors" AS "books_translator_count" ON (("books_count"."translator_id" = "books_translator_count"."id") AND "books_translator_count"."id" IS NOT NULL) GROUP BY "authors"."id" HAVING ((COUNT("books_translator_count"."id") >= 1 AND COUNT("books_translator_count"."id") <= 1) OR (COUNT("books_count"."id") >= 1 AND COUNT("books_count"."id") <= 1))) temp; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any" ON ( + "authors"."id" = "books_any"."author_id" + ) + LEFT JOIN "public"."authors" AS "books_translator_any" ON ( + "books_any"."translator_id" = "books_translator_any"."id" + ) +WHERE + ( + ("books_any"."title" = 'Book 1') + AND ( + "books_translator_any"."id" IS NULL + ) + ) +GROUP BY + "authors"."id"; + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any" ON ( + "authors"."id" = "books_any"."author_id" + ) + LEFT JOIN "public"."authors" AS "books_translator_any" ON ( + "books_any"."translator_id" = "books_translator_any"."id" + ) + WHERE + ( + ("books_any"."title" = 'Book 1') + AND ( + "books_translator_any"."id" IS NULL + ) + ) + GROUP BY + "authors"."id" + ) temp; + +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_count" ON ( + ( + "authors"."id" = "books_count"."author_id" + ) + OR ( + ( + "authors"."id" = "books_count"."author_id" + ) + AND "books_count"."price" < 100 + ) + ) + LEFT JOIN "public"."authors" AS "books_translator_count" ON ( + ( + "books_count"."translator_id" = "books_translator_count"."id" + ) + AND "books_translator_count"."id" IS NOT NULL + ) +GROUP BY + "authors"."id" +HAVING + ( + ( + COUNT("books_translator_count"."id") >= 1 + AND COUNT("books_translator_count"."id") <= 1 + ) + OR ( + COUNT("books_count"."id") >= 1 + AND COUNT("books_count"."id") <= 1 + ) + ); + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_count" ON ( + ( + "authors"."id" = "books_count"."author_id" + ) + OR ( + ( + "authors"."id" = "books_count"."author_id" + ) + AND "books_count"."price" < 100 + ) + ) + LEFT JOIN "public"."authors" AS "books_translator_count" ON ( + ( + "books_count"."translator_id" = "books_translator_count"."id" + ) + AND "books_translator_count"."id" IS NOT NULL + ) + GROUP BY + "authors"."id" + HAVING + ( + ( + COUNT("books_translator_count"."id") >= 1 + AND COUNT("books_translator_count"."id") <= 1 + ) + OR ( + COUNT("books_count"."id") >= 1 + AND COUNT("books_count"."id") <= 1 + ) + ) + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testCountAggregator.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testCountAggregator.sql index a651421c..2fbe4717 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testCountAggregator.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testCountAggregator.sql @@ -1,4 +1,85 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_count" ON (("authors"."id" = "books_count"."author_id") AND "books_count"."price" >= 50) GROUP BY "authors"."id" HAVING ((COUNT("books_count"."id") >= 2)); -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_count" ON (("authors"."id" = "books_count"."author_id") AND "books_count"."price" >= 50) GROUP BY "authors"."id" HAVING ((COUNT("books_count"."id") >= 2))) temp; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_count" ON (("authors"."id" = "books_count"."author_id") AND "books_count"."price" >= 51) GROUP BY "authors"."id" HAVING ((COUNT("books_count"."id") <= 1)); -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_count" ON (("authors"."id" = "books_count"."author_id") AND "books_count"."price" >= 51) GROUP BY "authors"."id" HAVING ((COUNT("books_count"."id") <= 1))) temp; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_count" ON ( + ( + "authors"."id" = "books_count"."author_id" + ) + AND "books_count"."price" >= 50 + ) +GROUP BY + "authors"."id" +HAVING + ( + ( + COUNT("books_count"."id") >= 2 + ) + ); + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_count" ON ( + ( + "authors"."id" = "books_count"."author_id" + ) + AND "books_count"."price" >= 50 + ) + GROUP BY + "authors"."id" + HAVING + ( + ( + COUNT("books_count"."id") >= 2 + ) + ) + ) temp; + +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_count" ON ( + ( + "authors"."id" = "books_count"."author_id" + ) + AND "books_count"."price" >= 51 + ) +GROUP BY + "authors"."id" +HAVING + ( + ( + COUNT("books_count"."id") <= 1 + ) + ); + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_count" ON ( + ( + "authors"."id" = "books_count"."author_id" + ) + AND "books_count"."price" >= 51 + ) + GROUP BY + "authors"."id" + HAVING + ( + ( + COUNT("books_count"."id") <= 1 + ) + ) + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testHasValueOrEmptyWithFunctions.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testHasValueOrEmptyWithFunctions.sql index d7561d22..ffbcab32 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testHasValueOrEmptyWithFunctions.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testHasValueOrEmptyWithFunctions.sql @@ -1,2 +1,70 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON (("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" IN (1)) LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") GROUP BY "books"."id" HAVING (((COUNT("tags_any"."id") > 0)) OR (COUNT("tags__COUNT"."id") = 0)); -SELECT COUNT(*) AS count FROM (SELECT "books"."id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON (("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" IN (1)) LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") GROUP BY "books"."id" HAVING (((COUNT("tags_any"."id") > 0)) OR (COUNT("tags__COUNT"."id") = 0))) temp; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" IN (1) + ) + LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ( + "books"."id" = "books_x_tags__COUNT"."book_id" + ) + LEFT JOIN "tags" AS "tags__COUNT" ON ( + "books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id" + ) +GROUP BY + "books"."id" +HAVING + ( + ( + ( + COUNT("tags_any"."id") > 0 + ) + ) + OR ( + COUNT("tags__COUNT"."id") = 0 + ) + ); + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "books"."id" + FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" IN (1) + ) + LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ( + "books"."id" = "books_x_tags__COUNT"."book_id" + ) + LEFT JOIN "tags" AS "tags__COUNT" ON ( + "books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id" + ) + GROUP BY + "books"."id" + HAVING + ( + ( + ( + COUNT("tags_any"."id") > 0 + ) + ) + OR ( + COUNT("tags__COUNT"."id") = 0 + ) + ) + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentAnyOverManyHasMany.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentAnyOverManyHasMany.sql index 72e8d9ee..6f2b8d45 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentAnyOverManyHasMany.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentAnyOverManyHasMany.sql @@ -1,2 +1,58 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_1" ON ("books"."id" = "books_x_tags_1"."book_id") LEFT JOIN "tags" AS "tags_1" ON ("books_x_tags_1"."tag_id" = "tags_1"."id") LEFT JOIN "books_x_tags" AS "books_x_tags_2" ON ("books"."id" = "books_x_tags_2"."book_id") LEFT JOIN "tags" AS "tags_2" ON ("books_x_tags_2"."tag_id" = "tags_2"."id") WHERE ((("tags_1"."id" = 1)) AND (("tags_2"."id" = 2))) GROUP BY "books"."id"; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_3" ON ("books"."id" = "books_x_tags_3"."book_id") LEFT JOIN "tags" AS "tags_3" ON ("books_x_tags_3"."tag_id" = "tags_3"."id") LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") WHERE ((("tags_3"."id" = 3))) GROUP BY "books"."id" HAVING ((COUNT("tags__COUNT"."id") = 1)); +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_1" ON ( + "books"."id" = "books_x_tags_1"."book_id" + ) + LEFT JOIN "tags" AS "tags_1" ON ( + "books_x_tags_1"."tag_id" = "tags_1"."id" + ) + LEFT JOIN "books_x_tags" AS "books_x_tags_2" ON ( + "books"."id" = "books_x_tags_2"."book_id" + ) + LEFT JOIN "tags" AS "tags_2" ON ( + "books_x_tags_2"."tag_id" = "tags_2"."id" + ) +WHERE + ( + ( + ("tags_1"."id" = 1) + ) + AND ( + ("tags_2"."id" = 2) + ) + ) +GROUP BY + "books"."id"; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_3" ON ( + "books"."id" = "books_x_tags_3"."book_id" + ) + LEFT JOIN "tags" AS "tags_3" ON ( + "books_x_tags_3"."tag_id" = "tags_3"."id" + ) + LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ( + "books"."id" = "books_x_tags__COUNT"."book_id" + ) + LEFT JOIN "tags" AS "tags__COUNT" ON ( + "books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id" + ) +WHERE + ( + ( + ("tags_3"."id" = 3) + ) + ) +GROUP BY + "books"."id" +HAVING + ( + ( + COUNT("tags__COUNT"."id") = 1 + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentAnyWithGroupingOverPk.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentAnyWithGroupingOverPk.sql index e905c9fa..d2fc9dd9 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentAnyWithGroupingOverPk.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentAnyWithGroupingOverPk.sql @@ -1,2 +1,65 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON ("books_x_tags_any"."tag_id" = "tags_any"."id") LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") WHERE ((("tags_any"."id" IN (2, 3)))) GROUP BY "books"."id" HAVING ((COUNT("tags__COUNT"."id") > 1)); -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON (("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" IN (2, 3)) LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") GROUP BY "books"."id" HAVING (((COUNT("tags_any"."id") > 0)) OR (COUNT("tags__COUNT"."id") > 1)); +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ( + "books"."id" = "books_x_tags__COUNT"."book_id" + ) + LEFT JOIN "tags" AS "tags__COUNT" ON ( + "books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id" + ) +WHERE + ( + ( + ( + "tags_any"."id" IN (2, 3) + ) + ) + ) +GROUP BY + "books"."id" +HAVING + ( + ( + COUNT("tags__COUNT"."id") > 1 + ) + ); + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" IN (2, 3) + ) + LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ( + "books"."id" = "books_x_tags__COUNT"."book_id" + ) + LEFT JOIN "tags" AS "tags__COUNT" ON ( + "books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id" + ) +GROUP BY + "books"."id" +HAVING + ( + ( + ( + COUNT("tags_any"."id") > 0 + ) + ) + OR ( + COUNT("tags__COUNT"."id") > 1 + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentSelects.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentSelects.sql index 33290007..c2d50bd6 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentSelects.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testIndependentSelects.sql @@ -1,2 +1,52 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any1" ON ("authors"."id" = "books_any1"."author_id") LEFT JOIN "books" AS "books_any2" ON ("authors"."id" = "books_any2"."author_id") WHERE ((("books_any1"."title" = 'Book 1') AND ("books_any1"."price" = 50)) AND (("books_any2"."title" = 'Book 2') AND ("books_any2"."price" = 150))) GROUP BY "authors"."id"; -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any1" ON ("authors"."id" = "books_any1"."author_id") LEFT JOIN "books" AS "books_any2" ON ("authors"."id" = "books_any2"."author_id") WHERE ((("books_any1"."title" = 'Book 1') AND ("books_any1"."price" = 50)) AND (("books_any2"."title" = 'Book 2') AND ("books_any2"."price" = 150))) GROUP BY "authors"."id") temp; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any1" ON ( + "authors"."id" = "books_any1"."author_id" + ) + LEFT JOIN "books" AS "books_any2" ON ( + "authors"."id" = "books_any2"."author_id" + ) +WHERE + ( + ( + ("books_any1"."title" = 'Book 1') + AND ("books_any1"."price" = 50) + ) + AND ( + ("books_any2"."title" = 'Book 2') + AND ("books_any2"."price" = 150) + ) + ) +GROUP BY + "authors"."id"; + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any1" ON ( + "authors"."id" = "books_any1"."author_id" + ) + LEFT JOIN "books" AS "books_any2" ON ( + "authors"."id" = "books_any2"."author_id" + ) + WHERE + ( + ( + ("books_any1"."title" = 'Book 1') + AND ("books_any1"."price" = 50) + ) + AND ( + ("books_any2"."title" = 'Book 2') + AND ("books_any2"."price" = 150) + ) + ) + GROUP BY + "authors"."id" + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testNone.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testNone.sql index 6528c5ed..eff9ca4b 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testNone.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationJoinTest_testNone.sql @@ -1,2 +1,46 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_none" ON (("authors"."id" = "books_none"."author_id") AND "books_none"."title" = 'Book 1') GROUP BY "authors"."id" HAVING (((COUNT("books_none"."id") = 0))); -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_none" ON (("authors"."id" = "books_none"."author_id") AND "books_none"."title" = 'Book 1') GROUP BY "authors"."id" HAVING (((COUNT("books_none"."id") = 0)))) temp; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_none" ON ( + ( + "authors"."id" = "books_none"."author_id" + ) + AND "books_none"."title" = 'Book 1' + ) +GROUP BY + "authors"."id" +HAVING + ( + ( + ( + COUNT("books_none"."id") = 0 + ) + ) + ); + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_none" ON ( + ( + "authors"."id" = "books_none"."author_id" + ) + AND "books_none"."title" = 'Book 1' + ) + GROUP BY + "authors"."id" + HAVING + ( + ( + ( + COUNT("books_none"."id") = 0 + ) + ) + ) + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAggregationWithNoAggregateCondition.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAggregationWithNoAggregateCondition.sql index c197f74f..f1625145 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAggregationWithNoAggregateCondition.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAggregationWithNoAggregateCondition.sql @@ -1,2 +1,58 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any" ON (("authors"."id" = "books_any"."author_id") AND "books_any"."title" = 'Book 1') LEFT JOIN "tag_followers" AS "tagFollowers__COUNT" ON ("authors"."id" = "tagFollowers__COUNT"."author_id") GROUP BY "authors"."id" HAVING (((COUNT("books_any"."id") > 0)) OR (COUNT("tagFollowers__COUNT"."tag_id") <= 2)); -SELECT COUNT(*) AS count FROM (SELECT "authors"."id" FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books_any" ON (("authors"."id" = "books_any"."author_id") AND "books_any"."title" = 'Book 1') LEFT JOIN "tag_followers" AS "tagFollowers__COUNT" ON ("authors"."id" = "tagFollowers__COUNT"."author_id") GROUP BY "authors"."id" HAVING (((COUNT("books_any"."id") > 0)) OR (COUNT("tagFollowers__COUNT"."tag_id") <= 2))) temp; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any" ON ( + ( + "authors"."id" = "books_any"."author_id" + ) + AND "books_any"."title" = 'Book 1' + ) + LEFT JOIN "tag_followers" AS "tagFollowers__COUNT" ON ( + "authors"."id" = "tagFollowers__COUNT"."author_id" + ) +GROUP BY + "authors"."id" +HAVING + ( + ( + ( + COUNT("books_any"."id") > 0 + ) + ) + OR ( + COUNT("tagFollowers__COUNT"."tag_id") <= 2 + ) + ); + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "authors"."id" + FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books_any" ON ( + ( + "authors"."id" = "books_any"."author_id" + ) + AND "books_any"."title" = 'Book 1' + ) + LEFT JOIN "tag_followers" AS "tagFollowers__COUNT" ON ( + "authors"."id" = "tagFollowers__COUNT"."author_id" + ) + GROUP BY + "authors"."id" + HAVING + ( + ( + ( + COUNT("books_any"."id") > 0 + ) + ) + OR ( + COUNT("tagFollowers__COUNT"."tag_id") <= 2 + ) + ) + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAvg.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAvg.sql index 0959116b..3905a3bb 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAvg.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAvg.sql @@ -1,2 +1,31 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__AVG" ON ("authors"."id" = "books__AVG"."author_id") GROUP BY "authors"."id" HAVING (AVG("books__AVG"."price") < 110) ORDER BY "authors"."id" ASC; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__AVG" ON ("authors"."id" = "books__AVG"."author_id") GROUP BY "authors"."id" HAVING (AVG("books__AVG"."price") <= 120) ORDER BY "authors"."id" ASC; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__AVG" ON ( + "authors"."id" = "books__AVG"."author_id" + ) +GROUP BY + "authors"."id" +HAVING + ( + AVG("books__AVG"."price") < 110 + ) +ORDER BY + "authors"."id" ASC; + +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__AVG" ON ( + "authors"."id" = "books__AVG"."author_id" + ) +GROUP BY + "authors"."id" +HAVING + ( + AVG("books__AVG"."price") <= 120 + ) +ORDER BY + "authors"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAvgOnEmptyCollection.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAvgOnEmptyCollection.sql index d986cc3c..b6c1bf19 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAvgOnEmptyCollection.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testAvgOnEmptyCollection.sql @@ -2,4 +2,15 @@ START TRANSACTION; INSERT INTO "public"."authors" ("name", "born", "web", "favorite_author_id") VALUES ('Test 3', '2021-03-21 08:23:00.000000'::timestamp, 'http://www.example.com', NULL); SELECT CURRVAL('public.authors_id_seq'); COMMIT; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__AVG" ON ("authors"."id" = "books__AVG"."author_id") GROUP BY "authors"."id" ORDER BY AVG("books__AVG"."price") ASC NULLS FIRST, "authors"."id" ASC; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__AVG" ON ( + "authors"."id" = "books__AVG"."author_id" + ) +GROUP BY + "authors"."id" +ORDER BY + AVG("books__AVG"."price") ASC NULLS FIRST, + "authors"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testCount.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testCount.sql index db2482cf..5f418e20 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testCount.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testCount.sql @@ -1,3 +1,50 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") GROUP BY "books"."id" HAVING (COUNT("tags__COUNT"."id") >= 2) ORDER BY "books"."id" ASC; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") GROUP BY "books"."id" ORDER BY COUNT("tags__COUNT"."id") ASC, "books"."id" ASC; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") GROUP BY "books"."id" ORDER BY COUNT("tags__COUNT"."id") DESC, "books"."id" DESC; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ( + "books"."id" = "books_x_tags__COUNT"."book_id" + ) + LEFT JOIN "tags" AS "tags__COUNT" ON ( + "books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id" + ) +GROUP BY + "books"."id" +HAVING + ( + COUNT("tags__COUNT"."id") >= 2 + ) +ORDER BY + "books"."id" ASC; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ( + "books"."id" = "books_x_tags__COUNT"."book_id" + ) + LEFT JOIN "tags" AS "tags__COUNT" ON ( + "books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id" + ) +GROUP BY + "books"."id" +ORDER BY + COUNT("tags__COUNT"."id") ASC, + "books"."id" ASC; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ( + "books"."id" = "books_x_tags__COUNT"."book_id" + ) + LEFT JOIN "tags" AS "tags__COUNT" ON ( + "books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id" + ) +GROUP BY + "books"."id" +ORDER BY + COUNT("tags__COUNT"."id") DESC, + "books"."id" DESC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMax.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMax.sql index 3c4e0985..59c76a16 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMax.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMax.sql @@ -1 +1,15 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__MAX" ON ("authors"."id" = "books__MAX"."author_id") GROUP BY "authors"."id" HAVING (MAX("books__MAX"."price") > 150) ORDER BY "authors"."id" ASC; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__MAX" ON ( + "authors"."id" = "books__MAX"."author_id" + ) +GROUP BY + "authors"."id" +HAVING + ( + MAX("books__MAX"."price") > 150 + ) +ORDER BY + "authors"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMaxWithEmptyCollection.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMaxWithEmptyCollection.sql index 6de69613..00d28052 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMaxWithEmptyCollection.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMaxWithEmptyCollection.sql @@ -2,4 +2,15 @@ START TRANSACTION; INSERT INTO "public"."authors" ("name", "born", "web", "favorite_author_id") VALUES ('Test 3', '2021-03-21 08:23:00.000000'::timestamp, 'http://www.example.com', NULL); SELECT CURRVAL('public.authors_id_seq'); COMMIT; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__MAX" ON ("authors"."id" = "books__MAX"."author_id") GROUP BY "authors"."id" ORDER BY MAX("books__MAX"."price") ASC NULLS FIRST, "authors"."id" ASC; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__MAX" ON ( + "authors"."id" = "books__MAX"."author_id" + ) +GROUP BY + "authors"."id" +ORDER BY + MAX("books__MAX"."price") ASC NULLS FIRST, + "authors"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMin.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMin.sql index 8e1f5ae6..78f3b155 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMin.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMin.sql @@ -1 +1,15 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__MIN" ON ("authors"."id" = "books__MIN"."author_id") GROUP BY "authors"."id" HAVING (MIN("books__MIN"."price") < 50) ORDER BY "authors"."id" ASC; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__MIN" ON ( + "authors"."id" = "books__MIN"."author_id" + ) +GROUP BY + "authors"."id" +HAVING + ( + MIN("books__MIN"."price") < 50 + ) +ORDER BY + "authors"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMinWithEmptyCollection.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMinWithEmptyCollection.sql index 9704c068..b3a600f9 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMinWithEmptyCollection.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testMinWithEmptyCollection.sql @@ -2,4 +2,15 @@ START TRANSACTION; INSERT INTO "public"."authors" ("name", "born", "web", "favorite_author_id") VALUES ('Test 3', '2021-03-21 08:23:00.000000'::timestamp, 'http://www.example.com', NULL); SELECT CURRVAL('public.authors_id_seq'); COMMIT; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__MIN" ON ("authors"."id" = "books__MIN"."author_id") GROUP BY "authors"."id" ORDER BY MIN("books__MIN"."price") ASC NULLS FIRST, "authors"."id" ASC; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__MIN" ON ( + "authors"."id" = "books__MIN"."author_id" + ) +GROUP BY + "authors"."id" +ORDER BY + MIN("books__MIN"."price") ASC NULLS FIRST, + "authors"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testSum.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testSum.sql index 0dff1526..2ab07a4c 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testSum.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionAggregationTest_testSum.sql @@ -1 +1,15 @@ -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__SUM" ON ("authors"."id" = "books__SUM"."author_id") GROUP BY "authors"."id" HAVING (SUM("books__SUM"."price") <= 200) ORDER BY "authors"."id" ASC; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__SUM" ON ( + "authors"."id" = "books__SUM"."author_id" + ) +GROUP BY + "authors"."id" +HAVING + ( + SUM("books__SUM"."price") <= 200 + ) +ORDER BY + "authors"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionEmbeddablesTest_testInvalidExpression.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionEmbeddablesTest_testInvalidExpression.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionEmbeddablesTest_testInvalidExpression.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionEmbeddablesTest_testInvalidExpression.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionEmbeddablesTest_testOrderBy.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionEmbeddablesTest_testOrderBy.sql index a9b33d36..b0574a03 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionEmbeddablesTest_testOrderBy.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionEmbeddablesTest_testOrderBy.sql @@ -1,5 +1,26 @@ SELECT "books".* FROM "books" AS "books" ORDER BY "books"."price" ASC; SELECT "authors".* FROM "public"."authors" AS "authors" WHERE (("authors"."id" = 1)); SELECT "books".* FROM "books" AS "books" WHERE "books"."author_id" IN (1) ORDER BY "books"."id" DESC, "books"."price" DESC; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__MAX" ON ("authors"."id" = "books__MAX"."author_id") GROUP BY "authors"."id" ORDER BY MAX("books__MAX"."price") ASC; -SELECT "authors".* FROM "public"."authors" AS "authors" LEFT JOIN "books" AS "books__MIN" ON ("authors"."id" = "books__MIN"."author_id") GROUP BY "authors"."id" ORDER BY MIN("books__MIN"."price") ASC; +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__MAX" ON ( + "authors"."id" = "books__MAX"."author_id" + ) +GROUP BY + "authors"."id" +ORDER BY + MAX("books__MAX"."price") ASC; + +SELECT + "authors".* +FROM + "public"."authors" AS "authors" + LEFT JOIN "books" AS "books__MIN" ON ( + "authors"."id" = "books__MIN"."author_id" + ) +GROUP BY + "authors"."id" +ORDER BY + MIN("books__MIN"."price") ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionHavingTest_testHavingWithSameNamedColumnsInGroupBy.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionHavingTest_testHavingWithSameNamedColumnsInGroupBy.sql index f3a1315c..d130a465 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionHavingTest_testHavingWithSameNamedColumnsInGroupBy.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionHavingTest_testHavingWithSameNamedColumnsInGroupBy.sql @@ -1 +1,33 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON (("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" = 1) LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") LEFT JOIN "publishers" AS "publisher" ON ("books"."publisher_id" = "publisher"."publisher_id") GROUP BY "books"."id", "author"."name", "publisher"."name" HAVING (("author"."name" = 'Writer 2') OR ("publisher"."name" = 'Nextras publisher C') OR (COUNT("tags_any"."id") > 0)); +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" = 1 + ) + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) + LEFT JOIN "publishers" AS "publisher" ON ( + "books"."publisher_id" = "publisher"."publisher_id" + ) +GROUP BY + "books"."id", + "author"."name", + "publisher"."name" +HAVING + ( + ("author"."name" = 'Writer 2') + OR ( + "publisher"."name" = 'Nextras publisher C' + ) + OR ( + COUNT("tags_any"."id") > 0 + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testConditionsInDifferentJoinsAndSameTable.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testConditionsInDifferentJoinsAndSameTable.sql index 7a530b43..a379f0f8 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testConditionsInDifferentJoinsAndSameTable.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testConditionsInDifferentJoinsAndSameTable.sql @@ -5,4 +5,20 @@ START TRANSACTION; INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id", "publisher_id", "genre", "published_at", "printed_at", "price", "price_currency", "orig_price_cents", "orig_price_currency") VALUES ('Books 5', 1, 2, NULL, NULL, 1, 'fantasy', '2021-12-31 23:59:59.000000'::timestamp, NULL, NULL, NULL, NULL, NULL); SELECT CURRVAL('public.books_id_seq'); COMMIT; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") LEFT JOIN "public"."authors" AS "translator" ON ("books"."translator_id" = "translator"."id") WHERE (("author"."name" = 'Writer 1') AND ("translator"."web" = 'http://example.com/2')); +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) + LEFT JOIN "public"."authors" AS "translator" ON ( + "books"."translator_id" = "translator"."id" + ) +WHERE + ( + ("author"."name" = 'Writer 1') + AND ( + "translator"."web" = 'http://example.com/2' + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testConditionsInSameJoin.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testConditionsInSameJoin.sql index 380c1d71..9d9e132e 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testConditionsInSameJoin.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testConditionsInSameJoin.sql @@ -1 +1,14 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") WHERE (("author"."name" = 'Writer 1') AND ("author"."web" = 'http://example.com/1')); +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) +WHERE + ( + ("author"."name" = 'Writer 1') + AND ( + "author"."web" = 'http://example.com/1' + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testCountOnLimitedWithJoin.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testCountOnLimitedWithJoin.sql index fa30e3c5..b0cdb926 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testCountOnLimitedWithJoin.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testCountOnLimitedWithJoin.sql @@ -1,2 +1,42 @@ -SELECT COUNT(*) AS count FROM (SELECT "books"."id" FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") WHERE (("author"."name" = 'Writer 1')) ORDER BY "books"."id" ASC LIMIT 5) temp; -SELECT COUNT(*) AS count FROM (SELECT "tag_followers"."tag_id", "tag_followers"."author_id" FROM "tag_followers" AS "tag_followers" LEFT JOIN "tags" AS "tag" ON ("tag_followers"."tag_id" = "tag"."id") WHERE (("tag"."name" = 'Tag 1')) ORDER BY "tag_followers"."tag_id" ASC LIMIT 3) temp; +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "books"."id" + FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) + WHERE + ( + ("author"."name" = 'Writer 1') + ) + ORDER BY + "books"."id" ASC + LIMIT + 5 + ) temp; + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "tag_followers"."tag_id", + "tag_followers"."author_id" + FROM + "tag_followers" AS "tag_followers" + LEFT JOIN "tags" AS "tag" ON ( + "tag_followers"."tag_id" = "tag"."id" + ) + WHERE + ( + ("tag"."name" = 'Tag 1') + ) + ORDER BY + "tag_followers"."tag_id" ASC + LIMIT + 3 + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testDistinct.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testDistinct.sql index 00e24937..63c15aff 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testDistinct.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testDistinct.sql @@ -1 +1,20 @@ -SELECT "tag_followers".* FROM "tag_followers" AS "tag_followers" LEFT JOIN "tags" AS "tag" ON ("tag_followers"."tag_id" = "tag"."id") LEFT JOIN "books_x_tags" AS "tag_books_x_tags_any" ON ("tag"."id" = "tag_books_x_tags_any"."tag_id") LEFT JOIN "books" AS "tag_books_any" ON ("tag_books_x_tags_any"."book_id" = "tag_books_any"."id") WHERE (("tag_books_any"."id" = 1)) GROUP BY "tag_followers"."tag_id", "tag_followers"."author_id"; +SELECT + "tag_followers".* +FROM + "tag_followers" AS "tag_followers" + LEFT JOIN "tags" AS "tag" ON ( + "tag_followers"."tag_id" = "tag"."id" + ) + LEFT JOIN "books_x_tags" AS "tag_books_x_tags_any" ON ( + "tag"."id" = "tag_books_x_tags_any"."tag_id" + ) + LEFT JOIN "books" AS "tag_books_any" ON ( + "tag_books_x_tags_any"."book_id" = "tag_books_any"."id" + ) +WHERE + ( + ("tag_books_any"."id" = 1) + ) +GROUP BY + "tag_followers"."tag_id", + "tag_followers"."author_id"; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testJoinDifferentPath.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testJoinDifferentPath.sql index 5be9a873..e4f3d7b7 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testJoinDifferentPath.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testJoinDifferentPath.sql @@ -13,4 +13,26 @@ SELECT CURRVAL('public.eans_id_seq'); INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id", "publisher_id", "genre", "published_at", "printed_at", "price", "price_currency", "orig_price_cents", "orig_price_currency") VALUES ('Book 5', 1, NULL, 4, 2, 1, 'fantasy', '2021-12-31 23:59:59.000000'::timestamp, NULL, NULL, NULL, NULL, NULL); SELECT CURRVAL('public.books_id_seq'); COMMIT; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books" AS "nextPart" ON ("books"."next_part" = "nextPart"."id") LEFT JOIN "eans" AS "nextPart_ean" ON ("nextPart"."ean_id" = "nextPart_ean"."id") LEFT JOIN "books" AS "previousPart" ON ("books"."id" = "previousPart"."next_part") LEFT JOIN "eans" AS "previousPart_ean" ON ("previousPart"."ean_id" = "previousPart_ean"."id") WHERE (("nextPart_ean"."code" = '123') AND ("previousPart_ean"."code" = '456')); +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books" AS "nextPart" ON ( + "books"."next_part" = "nextPart"."id" + ) + LEFT JOIN "eans" AS "nextPart_ean" ON ( + "nextPart"."ean_id" = "nextPart_ean"."id" + ) + LEFT JOIN "books" AS "previousPart" ON ( + "books"."id" = "previousPart"."next_part" + ) + LEFT JOIN "eans" AS "previousPart_ean" ON ( + "previousPart"."ean_id" = "previousPart_ean"."id" + ) +WHERE + ( + ("nextPart_ean"."code" = '123') + AND ( + "previousPart_ean"."code" = '456' + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrdering.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrdering.sql index 9a480ecc..44252c50 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrdering.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrdering.sql @@ -1,2 +1,21 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") ORDER BY "author"."id" DESC, "books"."title" ASC; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") ORDER BY "author"."id" DESC, "books"."title" DESC; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) +ORDER BY + "author"."id" DESC, + "books"."title" ASC; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) +ORDER BY + "author"."id" DESC, + "books"."title" DESC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrderingMultiple.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrderingMultiple.sql index 9a480ecc..44252c50 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrderingMultiple.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrderingMultiple.sql @@ -1,2 +1,21 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") ORDER BY "author"."id" DESC, "books"."title" ASC; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") ORDER BY "author"."id" DESC, "books"."title" DESC; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) +ORDER BY + "author"."id" DESC, + "books"."title" ASC; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) +ORDER BY + "author"."id" DESC, + "books"."title" DESC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrderingWithOptionalProperty.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrderingWithOptionalProperty.sql index 15a5bb92..0dcfc863 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrderingWithOptionalProperty.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/CollectionTest_testOrderingWithOptionalProperty.sql @@ -1,4 +1,43 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "translator" ON ("books"."translator_id" = "translator"."id") ORDER BY "translator"."name" ASC NULLS FIRST, "books"."id" ASC; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "translator" ON ("books"."translator_id" = "translator"."id") ORDER BY "translator"."name" DESC, "books"."id" ASC; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "translator" ON ("books"."translator_id" = "translator"."id") ORDER BY "translator"."name" ASC, "books"."id" ASC; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "public"."authors" AS "translator" ON ("books"."translator_id" = "translator"."id") ORDER BY "translator"."name" DESC NULLS LAST, "books"."id" ASC; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "translator" ON ( + "books"."translator_id" = "translator"."id" + ) +ORDER BY + "translator"."name" ASC NULLS FIRST, + "books"."id" ASC; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "translator" ON ( + "books"."translator_id" = "translator"."id" + ) +ORDER BY + "translator"."name" DESC, + "books"."id" ASC; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "translator" ON ( + "books"."translator_id" = "translator"."id" + ) +ORDER BY + "translator"."name" ASC, + "books"."id" ASC; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "translator" ON ( + "books"."translator_id" = "translator"."id" + ) +ORDER BY + "translator"."name" DESC NULLS LAST, + "books"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testManyHasOneJoin.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testManyHasOneJoin.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testManyHasOneJoin.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testManyHasOneJoin.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testOneHasManyJoin.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testOneHasManyJoin.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testOneHasManyJoin.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testOneHasManyJoin.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testOneHasOneJoin.sql b/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testOneHasOneJoin.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testOneHasOneJoin.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Collection/Functions/FetchPropertyFunctionTest_testOneHasOneJoin.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCloningTest_testCloningManyHasMany.sql b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCloningTest_testCloningManyHasMany.sql index a4287413..01048501 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCloningTest_testCloningManyHasMany.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCloningTest_testCloningManyHasMany.sql @@ -13,6 +13,16 @@ INSERT INTO "tags" ("name", "is_global") VALUES ('Tag 3', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (5, 4), (5, 5), (5, 6); COMMIT; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (4, 5, 6))); SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (5); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCloningTest_testCloningOneHasMany.sql b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCloningTest_testCloningOneHasMany.sql index 212968b8..c11aeb35 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCloningTest_testCloningOneHasMany.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCloningTest_testCloningOneHasMany.sql @@ -1,7 +1,17 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (1); SELECT "publishers".* FROM "publishers" AS "publishers" WHERE "publishers"."publisher_id" IN (1); @@ -10,4 +20,17 @@ INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id SELECT CURRVAL('public.books_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (5, 1), (5, 2); COMMIT; -SELECT "books_x_tags"."book_id", COUNT(DISTINCT "books_x_tags"."tag_id") AS "count" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5) GROUP BY "books_x_tags"."book_id"; +SELECT + "books_x_tags"."book_id", + COUNT( + DISTINCT "books_x_tags"."tag_id" + ) AS "count" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5) +GROUP BY + "books_x_tags"."book_id"; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testGetByIdWronglyUsedWithIndexedKeys.sql b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testGetByIdWronglyUsedWithIndexedKeys.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testGetByIdWronglyUsedWithIndexedKeys.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testGetByIdWronglyUsedWithIndexedKeys.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testSetIdOnlyPartially.sql b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testSetIdOnlyPartially.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testSetIdOnlyPartially.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testSetIdOnlyPartially.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testSetIdWithInsufficientParameters.sql b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testSetIdWithInsufficientParameters.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testSetIdWithInsufficientParameters.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Entity/EntityCompositePKTest_testSetIdWithInsufficientParameters.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testMHMRelations.sql b/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testMHMRelations.sql index 36ff101b..9e23ae11 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testMHMRelations.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testMHMRelations.sql @@ -1,8 +1,28 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 2)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (2); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (2); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2, 3))); DELETE FROM "books_x_tags" WHERE book_id = 2 AND tag_id = 3; SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (2))); SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2, 3))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (2); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (2); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testMHMRelations2.sql b/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testMHMRelations2.sql index 0c4c4ac6..2a2e6245 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testMHMRelations2.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testMHMRelations2.sql @@ -1,8 +1,28 @@ SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 3)); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (3); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (3); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (2, 3))); DELETE FROM "books_x_tags" WHERE book_id = 2 AND tag_id = 3; SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (2, 3))); SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (3))); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (3); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (3); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (3))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testTrackedMHM.sql b/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testTrackedMHM.sql index b066229b..eff8b31d 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testTrackedMHM.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Model/ModelRefreshAllTest_testTrackedMHM.sql @@ -1,13 +1,33 @@ SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 3)); SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 2)); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (3); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (3); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (2, 3))); START TRANSACTION; UPDATE "books" SET "title" = 'abc' WHERE "id" = 2; COMMIT; SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (2, 3))); SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (3))); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (3); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (3); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (2, 3))); START TRANSACTION; UPDATE "books" SET "title" = 'xyz' WHERE "id" = 2; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testBasics.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testBasics.sql index ca301dd9..f24af8f0 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testBasics.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testBasics.sql @@ -9,6 +9,29 @@ INSERT INTO "tags" ("name", "is_global") VALUES ('Awesome', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (5, 4); COMMIT; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (4))); -SELECT "books_x_tags"."book_id", COUNT(DISTINCT "books_x_tags"."tag_id") AS "count" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5) GROUP BY "books_x_tags"."book_id"; +SELECT + "books_x_tags"."book_id", + COUNT( + DISTINCT "books_x_tags"."tag_id" + ) AS "count" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5) +GROUP BY + "books_x_tags"."book_id"; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testDeepTraversalHasOne.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testDeepTraversalHasOne.sql index f9304f7b..649b4cf1 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testDeepTraversalHasOne.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testDeepTraversalHasOne.sql @@ -1,4 +1,14 @@ SELECT "tags".* FROM "tags" AS "tags"; -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (1, 2, 3); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (1, 2, 3); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1, 2, 3))); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1, 2); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testDeepTraversalManyHasMany.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testDeepTraversalManyHasMany.sql index d4e60498..6ebc60df 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testDeepTraversalManyHasMany.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testDeepTraversalManyHasMany.sql @@ -1,4 +1,14 @@ SELECT "authors".* FROM "public"."authors" AS "authors"; SELECT "books".* FROM "books" AS "books" WHERE "books"."author_id" IN (1, 2) ORDER BY "books"."id" DESC; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (4, 3, 2, 1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (4, 3, 2, 1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 3))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testSetRelationships.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testSetRelationships.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testSetRelationships.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/EntityRelationshipsTest_testSetRelationships.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipCyclicTest_testCycleCheck.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipCyclicTest_testCycleCheck.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipCyclicTest_testCycleCheck.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipCyclicTest_testCycleCheck.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCache.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCache.sql index fb03c9de..3dbe4d51 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCache.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCache.sql @@ -1,7 +1,86 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."name" != 'Tag 1'))) AND ("books_x_tags"."book_id" IN (1)) ORDER BY "tags"."id" ASC; +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."name" != 'Tag 1') + ) + ) + AND ( + "books_x_tags"."book_id" IN (1) + ) +ORDER BY + "tags"."id" ASC; + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2))); -SELECT "books_x_tags"."book_id", COUNT(DISTINCT "books_x_tags"."tag_id") AS "count" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."name" != 'Tag 1'))) AND ("books_x_tags"."book_id" IN (1)) GROUP BY "books_x_tags"."book_id"; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."name" != 'Tag 3'))) AND ("books_x_tags"."book_id" IN (1)) ORDER BY "tags"."id" ASC; +SELECT + "books_x_tags"."book_id", + COUNT( + DISTINCT "books_x_tags"."tag_id" + ) AS "count" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."name" != 'Tag 1') + ) + ) + AND ( + "books_x_tags"."book_id" IN (1) + ) +GROUP BY + "books_x_tags"."book_id"; + +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."name" != 'Tag 3') + ) + ) + AND ( + "books_x_tags"."book_id" IN (1) + ) +ORDER BY + "tags"."id" ASC; + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); -SELECT "books_x_tags"."book_id", COUNT(DISTINCT "books_x_tags"."tag_id") AS "count" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."name" != 'Tag 3'))) AND ("books_x_tags"."book_id" IN (1)) GROUP BY "books_x_tags"."book_id"; +SELECT + "books_x_tags"."book_id", + COUNT( + DISTINCT "books_x_tags"."tag_id" + ) AS "count" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."name" != 'Tag 3') + ) + ) + AND ( + "books_x_tags"."book_id" IN (1) + ) +GROUP BY + "books_x_tags"."book_id"; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCaching.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCaching.sql index cbafac1a..2a068718 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCaching.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCaching.sql @@ -1,7 +1,40 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."name" = 'Tag 1'))) AND ("books_x_tags"."book_id" IN (1)); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."name" = 'Tag 1') + ) + ) + AND ( + "books_x_tags"."book_id" IN (1) + ); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1))); START TRANSACTION; UPDATE "tags" SET "name" = 'XXX' WHERE "id" = 1; COMMIT; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."name" = 'Tag 1'))) AND ("books_x_tags"."book_id" IN (1)); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."name" = 'Tag 1') + ) + ) + AND ( + "books_x_tags"."book_id" IN (1) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCachingPreload.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCachingPreload.sql index 158ec07f..9a7c7179 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCachingPreload.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCachingPreload.sql @@ -1,9 +1,70 @@ SELECT "books".* FROM "books" AS "books"; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1, 2, 3, 4); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1, 2, 3, 4); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 3))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."id" = 1))) AND ("books_x_tags"."book_id" IN (2)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."id" = 2))) AND ("books_x_tags"."book_id" IN (2)); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."id" = 1) + ) + ) + AND ( + "books_x_tags"."book_id" IN (2) + ); + +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."id" = 2) + ) + ) + AND ( + "books_x_tags"."book_id" IN (2) + ); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."id" = 3))) AND ("books_x_tags"."book_id" IN (2)); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ("tags"."id" = 3) + ) + ) + AND ( + "books_x_tags"."book_id" IN (2) + ); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (3))); SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 4)); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCollectionCountWithLimit.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCollectionCountWithLimit.sql index cbb8300f..b8c4f7dc 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCollectionCountWithLimit.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCollectionCountWithLimit.sql @@ -1,3 +1,21 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -(SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" = 1 ORDER BY "tags"."id" ASC LIMIT 1 OFFSET 1); +( + SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "books_x_tags"."book_id" = 1 + ORDER BY + "tags"."id" ASC + LIMIT + 1 + OFFSET + 1 +); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountAfterRemoveAndFlushAndCount.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountAfterRemoveAndFlushAndCount.sql index d10180c5..a913a37d 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountAfterRemoveAndFlushAndCount.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountAfterRemoveAndFlushAndCount.sql @@ -7,20 +7,70 @@ INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id SELECT CURRVAL('public.books_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (5, 4); COMMIT; -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (4); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (4); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (5))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (4))); SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (5); START TRANSACTION; DELETE FROM "books_x_tags" WHERE ("book_id", "tag_id") IN ((5, 4)); DELETE FROM "books" WHERE "id" = 5; -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (4); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (4); + COMMIT; -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (4); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (4); + START TRANSACTION; INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id", "publisher_id", "genre", "published_at", "printed_at", "price", "price_currency", "orig_price_cents", "orig_price_currency") VALUES ('The Wall III', 1, NULL, NULL, NULL, 1, 'fantasy', '2021-12-31 23:59:59.000000'::timestamp, NULL, NULL, NULL, NULL, NULL); SELECT CURRVAL('public.books_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (6, 4); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (4); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (4); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (6))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountStoredOnManyHasManyRelationshipCondition.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountStoredOnManyHasManyRelationshipCondition.sql index 07e2cca3..acb2b087 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountStoredOnManyHasManyRelationshipCondition.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountStoredOnManyHasManyRelationshipCondition.sql @@ -1,7 +1,124 @@ SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 1)); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE ((("author"."id" = 1))) AND ("books_x_tags"."tag_id" IN (1)); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + ( + ( + ("author"."id" = 1) + ) + ) + AND ( + "books_x_tags"."tag_id" IN (1) + ); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1))); -SELECT "books_x_tags"."tag_id", COUNT(DISTINCT "books_x_tags"."book_id") AS "count" FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE ((("author"."id" = 1))) AND ("books_x_tags"."tag_id" IN (1)) GROUP BY "books_x_tags"."tag_id"; -SELECT DISTINCT * FROM (SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") LEFT JOIN "tag_followers" AS "author_tagFollowers_any" ON ("author"."id" = "author_tagFollowers_any"."author_id") LEFT JOIN "public"."authors" AS "author_tagFollowers_author_any" ON ("author_tagFollowers_any"."author_id" = "author_tagFollowers_author_any"."id") LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE ((("author_tagFollowers_author_any"."id" = 1))) AND ("books_x_tags"."tag_id" IN (1)) GROUP BY "books"."id", "books"."title", "books_x_tags"."book_id", "books_x_tags"."tag_id" ORDER BY "books"."title" ASC) AS "__tmp"; +SELECT + "books_x_tags"."tag_id", + COUNT( + DISTINCT "books_x_tags"."book_id" + ) AS "count" +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + ( + ( + ("author"."id" = 1) + ) + ) + AND ( + "books_x_tags"."tag_id" IN (1) + ) +GROUP BY + "books_x_tags"."tag_id"; + +SELECT + DISTINCT * +FROM + ( + SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" + FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) + LEFT JOIN "tag_followers" AS "author_tagFollowers_any" ON ( + "author"."id" = "author_tagFollowers_any"."author_id" + ) + LEFT JOIN "public"."authors" AS "author_tagFollowers_author_any" ON ( + "author_tagFollowers_any"."author_id" = "author_tagFollowers_author_any"."id" + ) + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) + WHERE + ( + ( + ( + "author_tagFollowers_author_any"."id" = 1 + ) + ) + ) + AND ( + "books_x_tags"."tag_id" IN (1) + ) + GROUP BY + "books"."id", + "books"."title", + "books_x_tags"."book_id", + "books_x_tags"."tag_id" + ORDER BY + "books"."title" ASC + ) AS "__tmp"; + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1))); -SELECT "books_x_tags"."tag_id", COUNT(DISTINCT "books_x_tags"."book_id") AS "count" FROM "books" AS "books" LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") LEFT JOIN "tag_followers" AS "author_tagFollowers_any" ON ("author"."id" = "author_tagFollowers_any"."author_id") LEFT JOIN "public"."authors" AS "author_tagFollowers_author_any" ON ("author_tagFollowers_any"."author_id" = "author_tagFollowers_author_any"."id") LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE ((("author_tagFollowers_author_any"."id" = 1))) AND ("books_x_tags"."tag_id" IN (1)) GROUP BY "books"."id", "books"."title", "books_x_tags"."tag_id"; +SELECT + "books_x_tags"."tag_id", + COUNT( + DISTINCT "books_x_tags"."book_id" + ) AS "count" +FROM + "books" AS "books" + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) + LEFT JOIN "tag_followers" AS "author_tagFollowers_any" ON ( + "author"."id" = "author_tagFollowers_any"."author_id" + ) + LEFT JOIN "public"."authors" AS "author_tagFollowers_author_any" ON ( + "author_tagFollowers_any"."author_id" = "author_tagFollowers_author_any"."id" + ) + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + ( + ( + ( + "author_tagFollowers_author_any"."id" = 1 + ) + ) + ) + AND ( + "books_x_tags"."tag_id" IN (1) + ) +GROUP BY + "books"."id", + "books"."title", + "books_x_tags"."tag_id"; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountStoredOnManyToManyCondition.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountStoredOnManyToManyCondition.sql index 037d8729..22287792 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountStoredOnManyToManyCondition.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testCountStoredOnManyToManyCondition.sql @@ -1 +1,21 @@ -SELECT COUNT(*) AS count FROM (SELECT "books"."id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON ("books_x_tags_any"."tag_id" = "tags_any"."id") WHERE (("tags_any"."name" = 'Tag 2')) GROUP BY "books"."id") temp; +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "books"."id" + FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + WHERE + ( + ("tags_any"."name" = 'Tag 2') + ) + GROUP BY + "books"."id" + ) temp; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testEmptyPreloadContainer.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testEmptyPreloadContainer.sql index 8261cea2..bd769517 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testEmptyPreloadContainer.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testEmptyPreloadContainer.sql @@ -1,8 +1,55 @@ SELECT "books".* FROM "books" AS "books" ORDER BY "books"."id" ASC; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1) ORDER BY "tags"."name" ASC; +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1) +ORDER BY + "tags"."name" ASC; + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (2) ORDER BY "tags"."name" ASC; +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (2) +ORDER BY + "tags"."name" ASC; + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2, 3))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (3) ORDER BY "tags"."name" ASC; +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (3) +ORDER BY + "tags"."name" ASC; + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (3))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (4) ORDER BY "tags"."name" ASC; +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (4) +ORDER BY + "tags"."name" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testJoinAcrossDifferentPaths.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testJoinAcrossDifferentPaths.sql index 8a07ca27..45282df8 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testJoinAcrossDifferentPaths.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testJoinAcrossDifferentPaths.sql @@ -1,7 +1,74 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON (("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."name" = 'Tag 1') LEFT JOIN "books" AS "nextPart" ON ("books"."next_part" = "nextPart"."id") LEFT JOIN "books_x_tags" AS "nextPart_books_x_tags_any" ON ("nextPart"."id" = "nextPart_books_x_tags_any"."book_id") LEFT JOIN "tags" AS "nextPart_tags_any" ON (("nextPart_books_x_tags_any"."tag_id" = "nextPart_tags_any"."id") AND "nextPart_tags_any"."name" = 'Tag 3') GROUP BY "books"."id" HAVING ((COUNT("tags_any"."id") > 0) OR (COUNT("nextPart_tags_any"."id") > 0)) ORDER BY "books"."id" ASC; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."name" = 'Tag 1' + ) + LEFT JOIN "books" AS "nextPart" ON ( + "books"."next_part" = "nextPart"."id" + ) + LEFT JOIN "books_x_tags" AS "nextPart_books_x_tags_any" ON ( + "nextPart"."id" = "nextPart_books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "nextPart_tags_any" ON ( + ( + "nextPart_books_x_tags_any"."tag_id" = "nextPart_tags_any"."id" + ) + AND "nextPart_tags_any"."name" = 'Tag 3' + ) +GROUP BY + "books"."id" +HAVING + ( + ( + COUNT("tags_any"."id") > 0 + ) + OR ( + COUNT("nextPart_tags_any"."id") > 0 + ) + ) +ORDER BY + "books"."id" ASC; + START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('Tag 5', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (4, 4); COMMIT; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON ("books_x_tags_any"."tag_id" = "tags_any"."id") LEFT JOIN "books" AS "nextPart" ON ("books"."next_part" = "nextPart"."id") LEFT JOIN "books_x_tags" AS "nextPart_books_x_tags_any" ON ("nextPart"."id" = "nextPart_books_x_tags_any"."book_id") LEFT JOIN "tags" AS "nextPart_tags_any" ON ("nextPart_books_x_tags_any"."tag_id" = "nextPart_tags_any"."id") WHERE (("tags_any"."name" = 'Tag 5') AND ("nextPart_tags_any"."name" = 'Tag 3')) GROUP BY "books"."id" ORDER BY "books"."id" ASC; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + LEFT JOIN "books" AS "nextPart" ON ( + "books"."next_part" = "nextPart"."id" + ) + LEFT JOIN "books_x_tags" AS "nextPart_books_x_tags_any" ON ( + "nextPart"."id" = "nextPart_books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "nextPart_tags_any" ON ( + "nextPart_books_x_tags_any"."tag_id" = "nextPart_tags_any"."id" + ) +WHERE + ( + ("tags_any"."name" = 'Tag 5') + AND ( + "nextPart_tags_any"."name" = 'Tag 3' + ) + ) +GROUP BY + "books"."id" +ORDER BY + "books"."id" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testLimit.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testLimit.sql index 21cc3a19..63166c64 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testLimit.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testLimit.sql @@ -4,6 +4,151 @@ START TRANSACTION; INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 3); COMMIT; SELECT "books".* FROM "books" AS "books" ORDER BY "books"."id" ASC; -(SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" = 1 ORDER BY "tags"."name" DESC LIMIT 2) UNION ALL (SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" = 2 ORDER BY "tags"."name" DESC LIMIT 2) UNION ALL (SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" = 3 ORDER BY "tags"."name" DESC LIMIT 2) UNION ALL (SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" = 4 ORDER BY "tags"."name" DESC LIMIT 2); +( + SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "books_x_tags"."book_id" = 1 + ORDER BY + "tags"."name" DESC + LIMIT + 2 +) +UNION ALL + ( + SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "books_x_tags"."book_id" = 2 + ORDER BY + "tags"."name" DESC + LIMIT + 2 + ) +UNION ALL + ( + SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "books_x_tags"."book_id" = 3 + ORDER BY + "tags"."name" DESC + LIMIT + 2 + ) +UNION ALL + ( + SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "books_x_tags"."book_id" = 4 + ORDER BY + "tags"."name" DESC + LIMIT + 2 + ); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2, 3))); -(SELECT 1 AS "book_id", COUNT(*) AS "count" FROM (SELECT "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "book_id" = 1 LIMIT 2) "temp") UNION ALL (SELECT 2 AS "book_id", COUNT(*) AS "count" FROM (SELECT "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "book_id" = 2 LIMIT 2) "temp") UNION ALL (SELECT 3 AS "book_id", COUNT(*) AS "count" FROM (SELECT "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "book_id" = 3 LIMIT 2) "temp") UNION ALL (SELECT 4 AS "book_id", COUNT(*) AS "count" FROM (SELECT "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "book_id" = 4 LIMIT 2) "temp"); +( + SELECT + 1 AS "book_id", + COUNT(*) AS "count" + FROM + ( + SELECT + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "book_id" = 1 + LIMIT + 2 + ) "temp" +) +UNION ALL + ( + SELECT + 2 AS "book_id", + COUNT(*) AS "count" + FROM + ( + SELECT + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "book_id" = 2 + LIMIT + 2 + ) "temp" + ) +UNION ALL + ( + SELECT + 3 AS "book_id", + COUNT(*) AS "count" + FROM + ( + SELECT + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "book_id" = 3 + LIMIT + 2 + ) "temp" + ) +UNION ALL + ( + SELECT + 4 AS "book_id", + COUNT(*) AS "count" + FROM + ( + SELECT + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "book_id" = 4 + LIMIT + 2 + ) "temp" + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testRawValue.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testRawValue.sql index 98dc40e3..b57c9f4e 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testRawValue.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testRawValue.sql @@ -1,7 +1,36 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."id" NOT IN (1)))) AND ("books_x_tags"."book_id" IN (1)); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ( + "tags"."id" NOT IN (1) + ) + ) + ) + AND ( + "books_x_tags"."book_id" IN (1) + ); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2))); START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('Test tag', 'y'); @@ -9,10 +38,48 @@ SELECT CURRVAL('public.tags_id_seq'); DELETE FROM "books_x_tags" WHERE ("book_id", "tag_id") IN ((1, 1)); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4); COMMIT; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2, 4))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE ((("tags"."id" NOT IN (2, 4)))) AND ("books_x_tags"."book_id" IN (1)); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + ( + ( + ( + "tags"."id" NOT IN (2, 4) + ) + ) + ) + AND ( + "books_x_tags"."book_id" IN (1) + ); + START TRANSACTION; DELETE FROM "books_x_tags" WHERE ("book_id", "tag_id") IN ((1, 2), (1, 4)); COMMIT; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testRemove.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testRemove.sql index 74837084..61a27b70 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testRemove.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testRemove.sql @@ -3,6 +3,29 @@ SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 1)); START TRANSACTION; DELETE FROM "books_x_tags" WHERE ("book_id", "tag_id") IN ((1, 1)); COMMIT; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2))); -SELECT "books_x_tags"."book_id", COUNT(DISTINCT "books_x_tags"."tag_id") AS "count" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1) GROUP BY "books_x_tags"."book_id"; +SELECT + "books_x_tags"."book_id", + COUNT( + DISTINCT "books_x_tags"."tag_id" + ) AS "count" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1) +GROUP BY + "books_x_tags"."book_id"; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testSelfReferencing.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testSelfReferencing.sql index 92ae3ece..a2e99b9d 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testSelfReferencing.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testSelfReferencing.sql @@ -3,8 +3,27 @@ INSERT INTO "users" ("id") VALUES (123); COMMIT; START TRANSACTION; INSERT INTO "users" ("id") VALUES (124); -INSERT INTO "users_x_users" ("my_friends_id", "friends_with_me_id") VALUES (124, 123); +INSERT INTO "users_x_users" ("friends_with_me_id", "my_friends_id") VALUES (124, 123); COMMIT; -SELECT "users_x_users"."my_friends_id", "users_x_users"."friends_with_me_id" FROM "users" AS "users" LEFT JOIN "users_x_users" AS "users_x_users" ON ("users_x_users"."my_friends_id" = "users"."id") WHERE "users_x_users"."friends_with_me_id" IN (123); +SELECT + "users_x_users"."friends_with_me_id", + "users_x_users"."my_friends_id" +FROM + "users" AS "users" + LEFT JOIN "users_x_users" AS "users_x_users" ON ( + "users_x_users"."friends_with_me_id" = "users"."id" + ) +WHERE + "users_x_users"."my_friends_id" IN (123); + SELECT "users".* FROM "users" AS "users" WHERE (("users"."id" IN (124))); -SELECT "users_x_users"."friends_with_me_id", "users_x_users"."my_friends_id" FROM "users" AS "users" LEFT JOIN "users_x_users" AS "users_x_users" ON ("users_x_users"."friends_with_me_id" = "users"."id") WHERE "users_x_users"."my_friends_id" IN (123); +SELECT + "users_x_users"."my_friends_id", + "users_x_users"."friends_with_me_id" +FROM + "users" AS "users" + LEFT JOIN "users_x_users" AS "users_x_users" ON ( + "users_x_users"."my_friends_id" = "users"."id" + ) +WHERE + "users_x_users"."friends_with_me_id" IN (123); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testSymmetricRelationship.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testSymmetricRelationship.sql index 7389d19a..521bcbe2 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testSymmetricRelationship.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasManyTest_testSymmetricRelationship.sql @@ -1,5 +1,15 @@ SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 2)); SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 2)); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (2); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (2); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1, 2))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasOneTest_testProperAggregation.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasOneTest_testProperAggregation.sql index b62177e6..7205e232 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasOneTest_testProperAggregation.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipManyHasOneTest_testProperAggregation.sql @@ -1,2 +1,53 @@ -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON ("books_x_tags_any"."tag_id" = "tags_any"."id") LEFT JOIN "publishers" AS "publisher" ON ("books"."publisher_id" = "publisher"."publisher_id") WHERE (("tags_any"."id" = 1) AND ("publisher"."name" = 'Nextras publisher A')) GROUP BY "books"."id"; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_none" ON ("books"."id" = "books_x_tags_none"."book_id") LEFT JOIN "tags" AS "tags_none" ON (("books_x_tags_none"."tag_id" = "tags_none"."id") AND "tags_none"."id" = 1) LEFT JOIN "publishers" AS "publisher" ON ("books"."publisher_id" = "publisher"."publisher_id") WHERE (("publisher"."name" = 'Nextras publisher A')) GROUP BY "books"."id" HAVING ((COUNT("tags_none"."id") = 0)); +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + LEFT JOIN "publishers" AS "publisher" ON ( + "books"."publisher_id" = "publisher"."publisher_id" + ) +WHERE + ( + ("tags_any"."id" = 1) + AND ( + "publisher"."name" = 'Nextras publisher A' + ) + ) +GROUP BY + "books"."id"; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_none" ON ( + "books"."id" = "books_x_tags_none"."book_id" + ) + LEFT JOIN "tags" AS "tags_none" ON ( + ( + "books_x_tags_none"."tag_id" = "tags_none"."id" + ) + AND "tags_none"."id" = 1 + ) + LEFT JOIN "publishers" AS "publisher" ON ( + "books"."publisher_id" = "publisher"."publisher_id" + ) +WHERE + ( + ( + "publisher"."name" = 'Nextras publisher A' + ) + ) +GROUP BY + "books"."id" +HAVING + ( + ( + COUNT("tags_none"."id") = 0 + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyRemoveTest_testRemoveCollection.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyRemoveTest_testRemoveCollection.sql index cbeefb33..6a0c5fbe 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyRemoveTest_testRemoveCollection.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyRemoveTest_testRemoveCollection.sql @@ -6,7 +6,17 @@ INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id SELECT CURRVAL('public.books_id_seq'); COMMIT; SELECT "books".* FROM "books" AS "books" WHERE "books"."author_id" IN (3) ORDER BY "books"."id" DESC; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5); + SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (5); START TRANSACTION; DELETE FROM "books" WHERE "id" = 5; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyRemoveTest_testRemoveCollectionAndParent.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyRemoveTest_testRemoveCollectionAndParent.sql index dd47fa75..4d352dd3 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyRemoveTest_testRemoveCollectionAndParent.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyRemoveTest_testRemoveCollectionAndParent.sql @@ -6,7 +6,17 @@ INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id SELECT CURRVAL('public.books_id_seq'); COMMIT; SELECT "books".* FROM "books" AS "books" WHERE "books"."author_id" IN (3) ORDER BY "books"."id" DESC; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5); + SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (5); START TRANSACTION; DELETE FROM "books" WHERE "id" = 5; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testCountAfterRemoveAndFlushAndCount.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testCountAfterRemoveAndFlushAndCount.sql index e1059517..8f8098eb 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testCountAfterRemoveAndFlushAndCount.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testCountAfterRemoveAndFlushAndCount.sql @@ -7,7 +7,17 @@ INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id SELECT CURRVAL('public.books_id_seq'); COMMIT; SELECT "books".* FROM "books" AS "books" WHERE "books"."author_id" IN (3) ORDER BY "books"."id" DESC; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5); + SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (5); START TRANSACTION; DELETE FROM "books" WHERE "id" = 5; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testCountStoredOnOneHasManyRelationshipCondition.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testCountStoredOnOneHasManyRelationshipCondition.sql index 81622c38..b67e3899 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testCountStoredOnOneHasManyRelationshipCondition.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testCountStoredOnOneHasManyRelationshipCondition.sql @@ -1,3 +1,66 @@ SELECT "publishers".* FROM "publishers" AS "publishers" WHERE (("publishers"."publisher_id" = 1)); -SELECT "publisher_id", COUNT(DISTINCT "count") as "count" FROM (SELECT "books".*, "books"."id" AS "count" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON ("books_x_tags_any"."tag_id" = "tags_any"."id") WHERE ((("tags_any"."id" = 1))) AND ("books"."publisher_id" IN (1)) GROUP BY "books"."id") AS "temp" GROUP BY "publisher_id"; -SELECT "publisher_id", COUNT(DISTINCT "count") as "count" FROM (SELECT "books".*, "books"."id" AS "count" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON (("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" = 1) WHERE "books"."publisher_id" IN (1) GROUP BY "books"."id", "books"."title" HAVING (("books"."title" = 'Book 1') OR (COUNT("tags_any"."id") > 0))) AS "temp" GROUP BY "publisher_id"; +SELECT + "publisher_id", + COUNT(DISTINCT "count") as "count" +FROM + ( + SELECT + "books".*, + "books"."id" AS "count" + FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + WHERE + ( + ( + ("tags_any"."id" = 1) + ) + ) + AND ( + "books"."publisher_id" IN (1) + ) + GROUP BY + "books"."id" + ) AS "temp" +GROUP BY + "publisher_id"; + +SELECT + "publisher_id", + COUNT(DISTINCT "count") as "count" +FROM + ( + SELECT + "books".*, + "books"."id" AS "count" + FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" = 1 + ) + WHERE + "books"."publisher_id" IN (1) + GROUP BY + "books"."id", + "books"."title" + HAVING + ( + ("books"."title" = 'Book 1') + OR ( + COUNT("tags_any"."id") > 0 + ) + ) + ) AS "temp" +GROUP BY + "publisher_id"; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testDefaultOrderingOnEmptyCollection.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testDefaultOrderingOnEmptyCollection.sql index e69de29b..8b137891 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testDefaultOrderingOnEmptyCollection.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testDefaultOrderingOnEmptyCollection.sql @@ -0,0 +1 @@ + diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testOrderByDifferentTableColumnOnHasManyRelationshipCondition.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testOrderByDifferentTableColumnOnHasManyRelationshipCondition.sql index 0e2f0b50..368cc454 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testOrderByDifferentTableColumnOnHasManyRelationshipCondition.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testOrderByDifferentTableColumnOnHasManyRelationshipCondition.sql @@ -1,2 +1,28 @@ SELECT "publishers".* FROM "publishers" AS "publishers" WHERE (("publishers"."publisher_id" = 1)); -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON ("books_x_tags_any"."tag_id" = "tags_any"."id") LEFT JOIN "public"."authors" AS "author" ON ("books"."author_id" = "author"."id") WHERE ((("tags_any"."id" = 1))) AND ("books"."publisher_id" IN (1)) GROUP BY "books"."id", "author"."name" ORDER BY "author"."name" ASC; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + LEFT JOIN "public"."authors" AS "author" ON ( + "books"."author_id" = "author"."id" + ) +WHERE + ( + ( + ("tags_any"."id" = 1) + ) + ) + AND ( + "books"."publisher_id" IN (1) + ) +GROUP BY + "books"."id", + "author"."name" +ORDER BY + "author"."name" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testOrderingWithJoins.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testOrderingWithJoins.sql index 146e4df0..e40f261a 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testOrderingWithJoins.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testOrderingWithJoins.sql @@ -1,3 +1,12 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); -SELECT "books".* FROM "books" AS "books" LEFT JOIN "eans" AS "ean" ON ("books"."ean_id" = "ean"."id") WHERE "books"."author_id" IN (1) ORDER BY "books"."id" DESC, "ean"."code" ASC; +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "eans" AS "ean" ON ("books"."ean_id" = "ean"."id") +WHERE + "books"."author_id" IN (1) +ORDER BY + "books"."id" DESC, + "ean"."code" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testRawValue.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testRawValue.sql index dfcfd439..0fe1ca46 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testRawValue.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testRawValue.sql @@ -2,7 +2,17 @@ SELECT "authors".* FROM "public"."authors" AS "authors" WHERE (("authors"."id" = SELECT "books".* FROM "books" AS "books" WHERE "books"."author_id" IN (1) ORDER BY "books"."id" DESC; SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (1); SELECT "publishers".* FROM "publishers" AS "publishers" WHERE "publishers"."publisher_id" IN (1); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testSameTableJoinWithImplicitAggregation.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testSameTableJoinWithImplicitAggregation.sql index e1036c21..04370ed4 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testSameTableJoinWithImplicitAggregation.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasManyTest_testSameTableJoinWithImplicitAggregation.sql @@ -1,2 +1,78 @@ -SELECT COUNT(*) AS count FROM (SELECT "books"."id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON ((("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" IN (1)) OR (("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" IS NULL)) GROUP BY "books"."id" HAVING (((COUNT("tags_any"."id") > 0)) OR ((COUNT("tags_any"."id") > 0)))) temp; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ("books"."id" = "books_x_tags_any"."book_id") LEFT JOIN "tags" AS "tags_any" ON ((("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" IN (1)) OR (("books_x_tags_any"."tag_id" = "tags_any"."id") AND "tags_any"."id" IS NULL)) GROUP BY "books"."id" HAVING (((COUNT("tags_any"."id") > 0)) OR ((COUNT("tags_any"."id") > 0))); +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "books"."id" + FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" IN (1) + ) + OR ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" IS NULL + ) + ) + GROUP BY + "books"."id" + HAVING + ( + ( + ( + COUNT("tags_any"."id") > 0 + ) + ) + OR ( + ( + COUNT("tags_any"."id") > 0 + ) + ) + ) + ) temp; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags_any" ON ( + "books"."id" = "books_x_tags_any"."book_id" + ) + LEFT JOIN "tags" AS "tags_any" ON ( + ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" IN (1) + ) + OR ( + ( + "books_x_tags_any"."tag_id" = "tags_any"."id" + ) + AND "tags_any"."id" IS NULL + ) + ) +GROUP BY + "books"."id" +HAVING + ( + ( + ( + COUNT("tags_any"."id") > 0 + ) + ) + OR ( + ( + COUNT("tags_any"."id") > 0 + ) + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testCascadeRemove.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testCascadeRemove.sql index e48385b0..d9212578 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testCascadeRemove.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testCascadeRemove.sql @@ -8,7 +8,17 @@ SELECT "eans".* FROM "eans" AS "eans" WHERE (("eans"."id" = 1)); SELECT "books".* FROM "books" AS "books" WHERE "books"."ean_id" IN (1); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (1); SELECT "publishers".* FROM "publishers" AS "publishers" WHERE "publishers"."publisher_id" IN (1); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testCollection.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testCollection.sql index 1c7abe85..5c5e3430 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testCollection.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testCollection.sql @@ -6,5 +6,29 @@ SELECT CURRVAL('public.eans_id_seq'); INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id", "publisher_id", "genre", "published_at", "printed_at", "price", "price_currency", "orig_price_cents", "orig_price_currency") VALUES ('GoT', 1, NULL, NULL, 1, 1, 'fantasy', '2021-12-31 23:59:59.000000'::timestamp, NULL, NULL, NULL, NULL, NULL); SELECT CURRVAL('public.books_id_seq'); COMMIT; -SELECT COUNT(*) AS count FROM (SELECT "eans"."id" FROM "eans" AS "eans" LEFT JOIN "books" AS "book" ON ("eans"."id" = "book"."ean_id") WHERE (("book"."title" = 'GoT'))) temp; -SELECT "eans".* FROM "eans" AS "eans" LEFT JOIN "books" AS "book" ON ("eans"."id" = "book"."ean_id") WHERE (("book"."title" = 'GoT')) ORDER BY "book"."title" ASC; +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "eans"."id" + FROM + "eans" AS "eans" + LEFT JOIN "books" AS "book" ON ("eans"."id" = "book"."ean_id") + WHERE + ( + ("book"."title" = 'GoT') + ) + ) temp; + +SELECT + "eans".* +FROM + "eans" AS "eans" + LEFT JOIN "books" AS "book" ON ("eans"."id" = "book"."ean_id") +WHERE + ( + ("book"."title" = 'GoT') + ) +ORDER BY + "book"."title" ASC; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testQueryBuilder.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testQueryBuilder.sql index d76d4ee3..bc768875 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testQueryBuilder.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipOneHasOneTest_testQueryBuilder.sql @@ -6,7 +6,56 @@ SELECT CURRVAL('public.eans_id_seq'); INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id", "publisher_id", "genre", "published_at", "printed_at", "price", "price_currency", "orig_price_cents", "orig_price_currency") VALUES ('Games of Thrones I', 1, NULL, NULL, 1, 1, 'fantasy', '2021-12-31 23:59:59.000000'::timestamp, NULL, NULL, NULL, NULL, NULL); SELECT CURRVAL('public.books_id_seq'); COMMIT; -SELECT COUNT(*) AS count FROM (SELECT "books"."id" FROM "books" AS "books" LEFT JOIN "eans" AS "ean" ON ("books"."ean_id" = "ean"."id") WHERE (("ean"."code" = '1234'))) temp; -SELECT "books".* FROM "books" AS "books" LEFT JOIN "eans" AS "ean" ON ("books"."ean_id" = "ean"."id") WHERE (("ean"."code" = '1234')); -SELECT COUNT(*) AS count FROM (SELECT "eans"."id" FROM "eans" AS "eans" LEFT JOIN "books" AS "book" ON ("eans"."id" = "book"."ean_id") WHERE (("book"."title" = 'Games of Thrones I'))) temp; -SELECT "eans".* FROM "eans" AS "eans" LEFT JOIN "books" AS "book" ON ("eans"."id" = "book"."ean_id") WHERE (("book"."title" = 'Games of Thrones I')); +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "books"."id" + FROM + "books" AS "books" + LEFT JOIN "eans" AS "ean" ON ("books"."ean_id" = "ean"."id") + WHERE + ( + ("ean"."code" = '1234') + ) + ) temp; + +SELECT + "books".* +FROM + "books" AS "books" + LEFT JOIN "eans" AS "ean" ON ("books"."ean_id" = "ean"."id") +WHERE + ( + ("ean"."code" = '1234') + ); + +SELECT + COUNT(*) AS count +FROM + ( + SELECT + "eans"."id" + FROM + "eans" AS "eans" + LEFT JOIN "books" AS "book" ON ("eans"."id" = "book"."ean_id") + WHERE + ( + ( + "book"."title" = 'Games of Thrones I' + ) + ) + ) temp; + +SELECT + "eans".* +FROM + "eans" AS "eans" + LEFT JOIN "books" AS "book" ON ("eans"."id" = "book"."ean_id") +WHERE + ( + ( + "book"."title" = 'Games of Thrones I' + ) + ); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddA.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddA.sql index 08724de1..9363cf1d 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddA.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddA.sql @@ -3,6 +3,16 @@ START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #1', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4))); COMMIT; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddB.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddB.sql index a8d53f45..4ff47364 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddB.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddB.sql @@ -1,10 +1,30 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #1', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4))); COMMIT; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddC.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddC.sql index a8d53f45..4ff47364 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddC.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddC.sql @@ -1,10 +1,30 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #1', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4))); COMMIT; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddD.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddD.sql index f8b84616..388a4776 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddD.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddD.sql @@ -3,11 +3,31 @@ START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #1', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4))); INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #2', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 5); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4, 5))); COMMIT; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddE.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddE.sql index f8b84616..388a4776 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddE.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddE.sql @@ -3,11 +3,31 @@ START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #1', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4))); INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #2', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 5); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4, 5))); COMMIT; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddF.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddF.sql index 1dc51bd6..2c486e3f 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddF.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddF.sql @@ -6,6 +6,16 @@ INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4); INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #2', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 5); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4, 5))); COMMIT; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddH.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddH.sql index 028f3cc5..4b5c6e38 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddH.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddH.sql @@ -1,5 +1,15 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #1', 'y'); @@ -7,6 +17,16 @@ SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #2', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4), (1, 5); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4, 5))); COMMIT; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddI.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddI.sql index 58327396..7ce98ebd 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddI.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testAddI.sql @@ -1,15 +1,45 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); START TRANSACTION; INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #1', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 4); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4))); INSERT INTO "tags" ("name", "is_global") VALUES ('New Tag #2', 'y'); SELECT CURRVAL('public.tags_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (1, 5); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 4, 5))); COMMIT; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchDerivedCollectionA.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchDerivedCollectionA.sql index e463474b..5940f994 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchDerivedCollectionA.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchDerivedCollectionA.sql @@ -1,3 +1,13 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchDerivedCollectionB.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchDerivedCollectionB.sql index d34dc8eb..ff41a831 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchDerivedCollectionB.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchDerivedCollectionB.sql @@ -1,3 +1,19 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); -(SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" = 1 ORDER BY "tags"."id" ASC LIMIT 1); +( + SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" + FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) + WHERE + "books_x_tags"."book_id" = 1 + ORDER BY + "tags"."id" ASC + LIMIT + 1 +); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchExistingA.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchExistingA.sql index 1245a8ea..31921722 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchExistingA.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testFetchExistingA.sql @@ -1,10 +1,50 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 1)); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (1); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (1); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2))); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (2); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (2); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1, 2))); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (1, 2); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (1, 2); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1, 2, 3))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testRemoveA.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testRemoveA.sql index 675b4a98..4f660830 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testRemoveA.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testRemoveA.sql @@ -1,9 +1,29 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 2)); SELECT "tag_followers".* FROM "tag_followers" AS "tag_followers" WHERE "tag_followers"."tag_id" IN (2); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (2); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (2); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1, 2))); -SELECT "publishers_x_tags"."publisher_id", "publishers_x_tags"."tag_id" FROM "publishers" AS "publishers" LEFT JOIN "publishers_x_tags" AS "publishers_x_tags" ON ("publishers_x_tags"."publisher_id" = "publishers"."publisher_id") WHERE "publishers_x_tags"."tag_id" IN (2); +SELECT + "publishers_x_tags"."publisher_id", + "publishers_x_tags"."tag_id" +FROM + "publishers" AS "publishers" + LEFT JOIN "publishers_x_tags" AS "publishers_x_tags" ON ( + "publishers_x_tags"."publisher_id" = "publishers"."publisher_id" + ) +WHERE + "publishers_x_tags"."tag_id" IN (2); + SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (2); SELECT "tags".* FROM "tags" AS "tags" WHERE "tags"."id" IN (2); START TRANSACTION; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testRemoveB.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testRemoveB.sql index 085b00c3..8f469d3e 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testRemoveB.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsManyHasManyCollectionTest_testRemoveB.sql @@ -2,5 +2,15 @@ SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 1)); SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 2)); SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 3)); SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 1)); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (1); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (1); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyCollectionTest_testRemoveB.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyCollectionTest_testRemoveB.sql index 77397a12..b2bc0a3f 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyCollectionTest_testRemoveB.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyCollectionTest_testRemoveB.sql @@ -3,7 +3,17 @@ SELECT "authors".* FROM "public"."authors" AS "authors" WHERE (("authors"."id" = SELECT "authors".* FROM "public"."authors" AS "authors" WHERE (("authors"."id" = 2)); SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 2)); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (2); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (2); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2, 3))); SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (2); SELECT "publishers".* FROM "publishers" AS "publishers" WHERE "publishers"."publisher_id" IN (2); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyCollectionTest_testRemoveC.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyCollectionTest_testRemoveC.sql index 77397a12..b2bc0a3f 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyCollectionTest_testRemoveC.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyCollectionTest_testRemoveC.sql @@ -3,7 +3,17 @@ SELECT "authors".* FROM "public"."authors" AS "authors" WHERE (("authors"."id" = SELECT "authors".* FROM "public"."authors" AS "authors" WHERE (("authors"."id" = 2)); SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" = 2)); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (1); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (2); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (2); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (2, 3))); SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (2); SELECT "publishers".* FROM "publishers" AS "publishers" WHERE "publishers"."publisher_id" IN (2); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyPersistenceTest_testCollectionCount.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyPersistenceTest_testCollectionCount.sql index 1d1301d2..7392af3b 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyPersistenceTest_testCollectionCount.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyPersistenceTest_testCollectionCount.sql @@ -1,6 +1,16 @@ SELECT "authors".* FROM "public"."authors" AS "authors" WHERE (("authors"."id" = 2)); SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" = 2)); -SELECT "books_x_tags"."book_id", "books_x_tags"."tag_id" FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."book_id" = "books"."id") WHERE "books_x_tags"."tag_id" IN (2); +SELECT + "books_x_tags"."book_id", + "books_x_tags"."tag_id" +FROM + "books" AS "books" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."book_id" = "books"."id" + ) +WHERE + "books_x_tags"."tag_id" IN (2); + SELECT "books".* FROM "books" AS "books" WHERE (("books"."id" IN (1, 2))); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE (("authors"."id" = 1)); START TRANSACTION; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyPersistenceTest_testForeignKeyInNonConnectedRelationship.sql b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyPersistenceTest_testForeignKeyInNonConnectedRelationship.sql index e8966ae7..3fce8bd2 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyPersistenceTest_testForeignKeyInNonConnectedRelationship.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Relationships/RelationshipsOneHasManyPersistenceTest_testForeignKeyInNonConnectedRelationship.sql @@ -2,16 +2,46 @@ START TRANSACTION; INSERT INTO "users" ("id") VALUES (1); INSERT INTO "user_stats" ("user_id", "date", "value") VALUES (1, '2021-12-14 21:03:00.000000'::timestamptz, 3); INSERT INTO "users" ("id") VALUES (2); -INSERT INTO "users_x_users" ("my_friends_id", "friends_with_me_id") VALUES (2, 1); +INSERT INTO "users_x_users" ("friends_with_me_id", "my_friends_id") VALUES (2, 1); COMMIT; -SELECT "users_x_users"."friends_with_me_id", "users_x_users"."my_friends_id" FROM "users" AS "users" LEFT JOIN "users_x_users" AS "users_x_users" ON ("users_x_users"."friends_with_me_id" = "users"."id") WHERE "users_x_users"."my_friends_id" IN (1); -SELECT "users_x_users"."my_friends_id", "users_x_users"."friends_with_me_id" FROM "users" AS "users" LEFT JOIN "users_x_users" AS "users_x_users" ON ("users_x_users"."my_friends_id" = "users"."id") WHERE "users_x_users"."friends_with_me_id" IN (1); +SELECT + "users_x_users"."my_friends_id", + "users_x_users"."friends_with_me_id" +FROM + "users" AS "users" + LEFT JOIN "users_x_users" AS "users_x_users" ON ( + "users_x_users"."my_friends_id" = "users"."id" + ) +WHERE + "users_x_users"."friends_with_me_id" IN (1); + +SELECT + "users_x_users"."friends_with_me_id", + "users_x_users"."my_friends_id" +FROM + "users" AS "users" + LEFT JOIN "users_x_users" AS "users_x_users" ON ( + "users_x_users"."friends_with_me_id" = "users"."id" + ) +WHERE + "users_x_users"."my_friends_id" IN (1); + SELECT "users".* FROM "users" AS "users" WHERE (("users"."id" IN (2))); START TRANSACTION; -DELETE FROM "users_x_users" WHERE ("my_friends_id", "friends_with_me_id") IN ((2, 1)); +DELETE FROM "users_x_users" WHERE ("friends_with_me_id", "my_friends_id") IN ((2, 1)); DELETE FROM "users" WHERE "id" = 1; ROLLBACK; SELECT "users".* FROM "users" AS "users" WHERE (("users"."id" IN (1, 2))); SELECT "user_stats".* FROM "user_stats" AS "user_stats" WHERE ((("user_stats"."user_id", "user_stats"."date") IN ((1, '2021-12-14 21:03:00.000000'::timestamptz)))); -SELECT "users_x_users"."my_friends_id", "users_x_users"."friends_with_me_id" FROM "users" AS "users" LEFT JOIN "users_x_users" AS "users_x_users" ON ("users_x_users"."my_friends_id" = "users"."id") WHERE "users_x_users"."friends_with_me_id" IN (1, 2); +SELECT + "users_x_users"."friends_with_me_id", + "users_x_users"."my_friends_id" +FROM + "users" AS "users" + LEFT JOIN "users_x_users" AS "users_x_users" ON ( + "users_x_users"."friends_with_me_id" = "users"."id" + ) +WHERE + "users_x_users"."my_friends_id" IN (1, 2); + SELECT "users".* FROM "users" AS "users" WHERE (("users"."id" IN (2))); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryCascadeRemoveTest_testBasicCascadeRemove.sql b/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryCascadeRemoveTest_testBasicCascadeRemove.sql index f0f0a9da..97a5db93 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryCascadeRemoveTest_testBasicCascadeRemove.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryCascadeRemoveTest_testBasicCascadeRemove.sql @@ -11,7 +11,17 @@ SELECT "tag_followers".* FROM "tag_followers" AS "tag_followers" WHERE "tag_foll SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."favorite_author_id" IN (2); SELECT "books".* FROM "books" AS "books" WHERE "books"."translator_id" IN (2); SELECT "authors".* FROM "public"."authors" AS "authors" WHERE "authors"."id" IN (2); -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (4, 3); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (4, 3); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (3))); SELECT "books".* FROM "books" AS "books" WHERE "books"."id" IN (3); SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (4, 3); diff --git a/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryCascadeRemoveTest_testCascadeWithOneHasOneRelationship.sql b/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryCascadeRemoveTest_testCascadeWithOneHasOneRelationship.sql index c78b10d7..5a3b6bae 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryCascadeRemoveTest_testCascadeWithOneHasOneRelationship.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryCascadeRemoveTest_testCascadeWithOneHasOneRelationship.sql @@ -8,7 +8,17 @@ SELECT CURRVAL('public.publishers_publisher_id_seq'); INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id", "publisher_id", "genre", "published_at", "printed_at", "price", "price_currency", "orig_price_cents", "orig_price_currency") VALUES ('Title', 3, NULL, NULL, 1, 4, 'fantasy', '2021-12-31 23:59:59.000000'::timestamp, NULL, NULL, NULL, NULL, NULL); SELECT CURRVAL('public.books_id_seq'); COMMIT; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5); + SELECT "books".* FROM "books" AS "books" WHERE "books"."next_part" IN (5); START TRANSACTION; DELETE FROM "books" WHERE "id" = 5; diff --git a/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryPersistenceTest_testManyHasMany.sql b/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryPersistenceTest_testManyHasMany.sql index 93efe51f..c7ec2e11 100644 --- a/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryPersistenceTest_testManyHasMany.sql +++ b/tests/sqls/NextrasTests/Orm/Integration/Repository/RepositoryPersistenceTest_testManyHasMany.sql @@ -54,5 +54,15 @@ INSERT INTO "books" ("title", "author_id", "translator_id", "next_part", "ean_id SELECT CURRVAL('public.books_id_seq'); INSERT INTO "books_x_tags" ("book_id", "tag_id") VALUES (5, 1); COMMIT; -SELECT "books_x_tags"."tag_id", "books_x_tags"."book_id" FROM "tags" AS "tags" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books_x_tags"."tag_id" = "tags"."id") WHERE "books_x_tags"."book_id" IN (5); +SELECT + "books_x_tags"."tag_id", + "books_x_tags"."book_id" +FROM + "tags" AS "tags" + LEFT JOIN "books_x_tags" AS "books_x_tags" ON ( + "books_x_tags"."tag_id" = "tags"."id" + ) +WHERE + "books_x_tags"."book_id" IN (5); + SELECT "tags".* FROM "tags" AS "tags" WHERE (("tags"."id" IN (1)));