Skip to content

[6.x] Fix export sorting for joined alias columns#2104

Merged
luanfreitasdev merged 2 commits into
Power-Components:6.xfrom
johannesMEGABAD:6.x
May 12, 2026
Merged

[6.x] Fix export sorting for joined alias columns#2104
luanfreitasdev merged 2 commits into
Power-Components:6.xfrom
johannesMEGABAD:6.x

Conversation

@johannesMEGABAD

Copy link
Copy Markdown
Contributor

⚡ PowerGrid - Pull Request

  • Bug fix
  • Enhancement
  • New feature
  • Breaking change

Description

This PR fixes export sorting for joined or aliased database columns.

The normal table datasource query and the export query were resolving sort fields differently. The table query respected the existing ignoreTablePrefix behavior, so sorting by a selected alias such as nom_complet generated:

order by nom_complet asc

The export query always prefixed unqualified sort fields with the root table name, which generated:

order by lieu.nom_complet asc

That fails because nom_complet is a selected alias, not a real column on the root table.

The fix adds a shared sort-field resolver and uses it in the normal database sorting pipeline, synchronous exports, and queued exports. This keeps existing behavior for qualified fields like categories.name, preserves table-prefix behavior when ignoreTablePrefix is disabled, and keeps explicit export query options intact.

This PR also adds regression coverage for preparing export data sorted by a joined alias column.

The CSV export test helper was also adjusted to normalize \r\n, \n, and \r line endings instead of relying only on PHP_EOL. This makes the test assertion portable across environments and OpenSpout output line endings; it does not change export behavior.

Related Issue(s):

Aims to fix #2016

Documentation

This PR requires Documentation update?

  • Yes
  • No
  • I have already submitted a Documentation pull request.

Export queries were resolving sort fields differently from the normal
table datasource query. Unqualified sort fields were always prefixed
with the root table, so sorting an exported joined/aliased column like
`nom_complet` produced `lieu.nom_complet` instead of `nom_complet`.

Add a shared sort-field resolver and use it in both datasource sorting
and export paths, including queued exports. This keeps qualified fields,
table-prefix behavior, and explicit export query options intact.

Also add regression coverage for preparing export data sorted by a joined
alias column and normalize CSV line endings in the export test helper.
@luanfreitasdev

Copy link
Copy Markdown
Member

Awaiting pint/phpstan fixes

@luanfreitasdev luanfreitasdev marked this pull request as draft May 11, 2026 15:54
@johannesMEGABAD

Copy link
Copy Markdown
Contributor Author

Awaiting pint/phpstan fixes

Done

@luanfreitasdev luanfreitasdev marked this pull request as ready for review May 12, 2026 12:22
@luanfreitasdev luanfreitasdev merged commit e28492f into Power-Components:6.x May 12, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants