entity_query: sort: Column not found: Unknown column 'membership__field_year.field_year_value' I am using a entity_query, where I get a fatal error because the sort field is not found. The integer field (field_year exists) and exists in the database in the membership__field_year table in the field_year_value row.

query = $this-&gt;entity_query-&gt;get('membership');
$query-&gt;condition('field_membership_member', $this-&gt;member-&gt;id());
$query-&gt;condition('status', 1);
$query-&gt;sort('field_year' , 'DESC');


This is the error I get:


  Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'membership__field_year.field_year_value' in 'field list'


How do I sort on an integer field?
Found the culprit. Apparently I was calling $query-&gt;execute() twice.