nette / database

💾 A database layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.
https://doc.nette.org/database
Other
513 stars 108 forks source link

When `count(column)` is used on selection `group` and `having` conditions are ignored #283

Closed MartinMystikJonas closed 2 years ago

MartinMystikJonas commented 3 years ago

Version: all

Bug Description

When count(column) is used on selection group and having conditions are ignored

Steps To Reproduce

$selection->group('column1')->having('SUM(column2) > 0')->count('column1')

Expected Behavior

Return only rows where having conditions is met instead or all rows.

Possible Solution

Also copy group and having parameters in importConditions of SqlBuilder https://github.com/nette/database/blob/f0e379670b20f21a2d3d052d1c9cf1b6984210be/src/Database/Table/SqlBuilder.php#L239

Or is there reason why it is not copied?

MartinMystikJonas commented 3 years ago

I can prepare PR if proposed fix is ok.

dg commented 3 years ago

I can prepare PR if proposed fix is ok.

That would be great.