Change behavior of add_orderby

Created on 4 July 2010, almost 15 years ago
Updated 24 September 2024, 7 months ago

To make the patch in #470258: Groupwise maximum ('representative') relationships β†’ work properly, I had to slightly alter the behavior of the add_orderby method of views_plugin_query_default.

Currently, when the views query is built, add_orderby adds an aliased field into the SELECT clause (by adding a field to the View object) and then ORDERing by the aliased field: SELECT sort_field as sort_field_alias ... ORDER BY sort_field_alias).

As far as I know, the ORDER BY clause can simply use the table alias instead: table_alias.field.

Adding a field to the View (and consequently the select clause) should at best be an optional side-effect, and it seems to e like it just shouldn't happen there at all. My concern is that other code may depend on the field being added when add_orderby is called.

I generated a few views to test it out, a couple with complex relationships -- nothing broke, and the generated queries matched my hand-written queries pretty closely. But I definitely haven't tested it thoroughly.

πŸ› Bug report
Status

Closed: outdated

Version

11.0 πŸ”₯

Component

views.module

Created by

πŸ‡ΊπŸ‡ΈUnited States davideads

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

  • VDC

    Related to the Views in Drupal Core initiative.

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.

Production build 0.71.5 2024