-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add workaround for same-named columns in GROUP BY for MySQL
[closes #662]
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
/** | ||
* @testCase | ||
* @dataProvider ../../../databases.ini | ||
*/ | ||
|
||
namespace NextrasTests\Orm\Integration\Collection; | ||
|
||
|
||
use Nextras\Orm\Collection\ICollection; | ||
use NextrasTests\Orm\DataTestCase; | ||
use Tester\Assert; | ||
|
||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
|
||
|
||
class CollectionHavingTest extends DataTestCase | ||
{ | ||
public function testHavingWithSameNamedColumnsInGroupBy(): void | ||
{ | ||
// this is a test especially for MySQL and Orm's workaround | ||
$books = $this->orm->books->findBy([ | ||
ICollection::OR, | ||
'tags->id' => 1, | ||
'author->name' => 'Writer 1', | ||
'publisher->name' => 'Nextras publisher A', | ||
]); | ||
Assert::same($books->count(), 3); | ||
} | ||
} | ||
|
||
|
||
$test = new CollectionHavingTest(); | ||
$test->run(); |
1 change: 1 addition & 0 deletions
1
...m/Integration/Collection/CollectionHavingTest_testHavingWithSameNamedColumnsInGroupBy.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT "books".* FROM "books" AS "books" LEFT JOIN "books_x_tags" AS "books_x_tags" ON ("books"."id" = "books_x_tags"."book_id") LEFT JOIN "tags" AS "tags_any" ON (("books_x_tags"."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')); |