Document that EntityQuery->sort() allows specifying column

Created on 16 December 2019, over 5 years ago
Updated 2 July 2025, 4 days ago

You can sort by the start of a date range field like so:

$sessions_query = \Drupal::entityQuery('node');
$sessions_query->condition('type', 'session');
$sessions->sort('field_date_range');

However, you cannot specify sorting by the end date column, the query will crash:

$sessions->sort('field_date_range.field_date_range_end_value');

Using the contrib module time_range fails entirely:

$sessions->sort('field_time_range');

The columns are field_time_from and field_time_to. How are these supposed to be specified to integrate with EntityQuery->sort()?

📌 Task
Status

Needs work

Version

11.0 🔥

Component

entity system

Created by

🇺🇸United States mortona2k Seattle

Live updates comments and jobs are added and updated live.
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 mlncn Minneapolis, MN, USA

    This probably will not help 5½ years later but you were almost there— for entityQuery's purposes the column is not the full column name as it appears in the database table but only the part not redundant with the field name— so in the original post's example the field plus column indicator is not field_date_range.field_date_range_end_value but rather field_date_range.end_value, used like this:

      ->sort('field_date_range.end_value');
    

    This does not seem documented for sort() nor condition(), at least not in the docblock, and it really should be i think.

Production build 0.71.5 2024