Skip to content

Commit

Permalink
naive fix for duplicit entries in the result
Browse files Browse the repository at this point in the history
[refs #666]
  • Loading branch information
hrach committed Apr 11, 2024
1 parent dc728d9 commit cbb504a
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/Collection/Functions/JunctionFunctionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ protected function processQueryBuilderExpressionWithModifier(
$isHavingClause = $isHavingClause || $expression->isHavingClause;
}

if ($isHavingClause) {
$builder->distinct(true);
}

return new DbalExpressionResult(
expression: $dbalModifier,
args: [$processedArgs],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use Nextras\Orm\Collection\Aggregations\AnyAggregator;
use Nextras\Orm\Collection\Aggregations\CountAggregator;
use Nextras\Orm\Collection\Aggregations\NoneAggregator;
use Nextras\Orm\Collection\Functions\CompareEqualsFunction;
use Nextras\Orm\Collection\Functions\CompareGreaterThanFunction;
use Nextras\Orm\Collection\Functions\CountAggregateFunction;
use Nextras\Orm\Collection\ICollection;
use NextrasTests\Orm\DataTestCase;
Expand Down Expand Up @@ -67,6 +68,17 @@ class CollectionAggregationJoinTest extends DataTestCase
}


public function testIndependentAnyWithGroupingOverPk(): void
{
$books = $this->orm->books->findBy([
ICollection::AND,
[CompareGreaterThanFunction::class, [CountAggregateFunction::class, 'tags->id'], 1],
['tags->id' => [2, 3]],
]);
Assert::same(2, $books->count());
}


public function testAnyDependent(): void
{
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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 DISTINCT "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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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 DISTINCT "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 DISTINCT "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 DISTINCT "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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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 DISTINCT "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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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") GROUP BY "books"."id", "tags_3"."id" HAVING ((("tags_3"."id" = 3)) AND (COUNT("tags__COUNT"."id") = 1));
SELECT DISTINCT "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") GROUP BY "books"."id", "tags_3"."id" HAVING ((("tags_3"."id" = 3)) AND (COUNT("tags__COUNT"."id") = 1));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT DISTINCT "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") 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") GROUP BY "books"."id", "tags_any"."id" HAVING ((COUNT("tags__COUNT"."id") > 1) AND (("tags_any"."id" IN (2, 3))));
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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 DISTINCT "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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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 DISTINCT "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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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 DISTINCT "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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
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 DISTINCT "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;
Original file line number Diff line number Diff line change
@@ -1 +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" = 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 ((COUNT("tags_any"."id") > 0) OR ("author"."name" = 'Writer 1') OR ("publisher"."name" = 'Nextras publisher A'));
SELECT DISTINCT "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 ((COUNT("tags_any"."id") > 0) OR ("author"."name" = 'Writer 1') OR ("publisher"."name" = 'Nextras publisher A'));
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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 DISTINCT "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');
Expand Down
Loading

0 comments on commit cbb504a

Please sign in to comment.