Enhance drupal Drupal\Core\Entity\Query\Sql\Query::addSort allowing to reuse column from joined table

Created on 18 July 2016, about 9 years ago
Updated 11 August 2025, 12 days ago

Normally, the current implementation would create one INNER JOIN and one LEFT JOIN for the below query

    $results = $this->nodeStorage
      ->getQuery()
      ->exists('field_othertable.column')
      ->sort('field_othertable.column')
      ->execute()

This patch will improve the sorting functionality by reusing an existing column from the joined table.

In many cases, additional LEFT JOIN causes unexpected results. An example with a node column joined with a taxonomy with one-to-many or many-to-many cardinality.

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

entity system

Created by

πŸ‡ΉπŸ‡­Thailand iamake

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024