Skip to content

Duplicate column count #749

@mrceperka

Description

@mrceperka

Describe the bug
When calling $collection->countStored() on a table that has a column named count, invalid query is generated.

To Reproduce
Steps to reproduce the behavior. It could include:

  1. Create table with count column
  2. Call countStored()
$definition->keys->toCollection()
                   ->findBy(['state' => 'active'])
                   ->countStored()
  1. Query like this will be generated
SELECT
  `channel_definition_id`,
  COUNT(DISTINCT `count`) as `count`
FROM
  (
    SELECT
      `channel_definition_key`.*,
      `channel_definition_key`.`id` AS `count`
    FROM
      `channel_definition_key` AS `channel_definition_key`
    WHERE
      (`channel_definition_key`.`state` = 'active')
      AND (
        `channel_definition_key`.`channel_definition_id` IN (3)
      )
  ) AS `temp`
GROUP BY
  `channel_definition_id`;

Problem is in

 `channel_definition_key`.`id` AS `count`

Possibly related code:

Expected behavior
Working aliasing and valid query.

Versions::

  • Database: mariadb 10.11
  • Orm: v5.0.1
  • Dbal: v5.0.1

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions