-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paginator\Adapter\QueryBuilder Column not found: 1054 Unknown column in 'having clause' #13552
Comments
Hey @BenWil, I've had a go at reproducing this but to no avail. Can you please provide an example of your Here's a test that I've written (bearing in mind it's for Phalcon 4.0.x). // tests/integration/Paginator/Adapter/QueryBuilderCest.php
public function testIssue13552(IntegrationTester $I)
{
$this->setDiMysql();
$modelsManager = $this->getService('modelsManager');
$builder = $modelsManager->createBuilder()
->columns("COUNT(*) as robos_count")
->from(['Robots' => Robots::class])
->join(RobotsParts::class, "RobotsParts.robots_id = Robots.id", "RobotsParts", "LEFT")
->join(RobotsParts::class, "RobotsParts_2.robots_id = Robots.id", "RobotsParts_2", "LEFT")
->groupBy('Robots.id, RobotsParts.id, RobotsParts.parts_id, RobotsParts_2.id, RobotsParts_2.parts_id')
->having('MAX(Robots.year) > 1970')
;
// var_dump($builder->getQuery()->getSql());
$paginate = (new QueryBuilder(
[
"builder" => $builder,
"limit" => 1,
"page" => 2
]
))->paginate();
$I->assertEquals(4, $paginate->last);
$I->assertEquals(4, $paginate->total_items);
} Thank you :) |
Created tentative test for Issue phalcon#13552
The error occurs only with non-aggregate conditions in having clause Something like that should generate the error at the totalBuilder count query $builder = $modelsManager->createBuilder()
->columns("Robots.id")
->from(['Robots' => Robots::class])
->join(RobotsParts::class, "RobotsParts.robots_id = Robots.id", "RobotsParts", "LEFT")
->join(RobotsParts::class, "RobotsParts_2.robots_id = Robots.id", "RobotsParts_2", "LEFT")
->groupBy('Robots.id, RobotsParts.id, RobotsParts.parts_id, RobotsParts_2.id, RobotsParts_2.parts_id')
->having('Robots.id> 2')
; |
Created tentative test for Issue phalcon#13552
Thanks for getting back to me so promptly @BenWil. I can reproduce the issue now, I'll see what I can do :) |
Created tentative test for Issue #13552
@CameronHall I think the problem is not directly on the Paginator, but the query build itself. For exampel, when you do somthing like this $builder = $modelsManager->createBuilder()
->columns("Robots.id, RobotsParts.id, RobotsParts.parts_id, RobotsParts_2.id, RobotsParts_2.parts_id")
->from(['Robots' => Robots::class])
->join(RobotsParts::class, "RobotsParts.robots_id = Robots.id", "RobotsParts", "LEFT")
->join(RobotsParts::class, "RobotsParts_2.robots_id = Robots.id", "RobotsParts_2", "LEFT")
->groupBy('Robots.id, RobotsParts.id, RobotsParts.parts_id, RobotsParts_2.id, RobotsParts_2.parts_id')
->having('Robots.id > 1')
; which is done for the total count calculation, it becomes like this in sql SELECT `RobotsParts_2`.`id` AS `id`, `RobotsParts_2`.`parts_id` AS `parts_id` FROM `phalcon_test`.`Robots` AS `Robots` ... that results in Unknown column in 'having clause' |
…phalcon into CameronHall-bugfix/issue-13552 * 'bugfix/issue-13552' of https://github.com/CameronHall/cphalcon: Fixed #13552: Overwriting columns with the same alias
* CameronHall-bugfix/issue-13552: Fixed tests Fixed #13552: Overwriting columns with the same alias
This has been addressed in #13653 Thank you @CameronHall and @BenWil |
When using
Paginator\Adapter\QueryBuilder
with multiple groups of fields with the same column name, the following behavior occursGROUP BY vc.id, se.id, vc.zip, pc.id
becomes
pc.id AS id, vc.zip AS zip
in the totalBuilder count query witch results in an unkonwn column exception.
I think the solution would be to define an alias for all fields when building the groupColumn
The text was updated successfully, but these errors were encountered: