Currently, the fieldOrderBy() method in an EntityFieldQuery will exclude any results where the field value is NULL.

This was originally discussed as a bug report in #1611438: fieldOrderBy filters out results with empty field values.

It was determined that the exclusion of NULL fields was by design for performance reasons.

It would be nice if an EFQ that orders by fields didn't exclude Entities with empty field values, but it needs to be accomplished in a way that doesn't degrade performance.

Comments

chx’s picture

To achieve this, you'd need to special case the query that doesn't join at all and use that for ordering. I do not see this as a core thing to do. I am not yet won't fixing it but I am close to that.

bxtaylor’s picture

If you foresee this as never being added, I'm fine with closing as a won't fix.

I created this issue based on @berdir's suggestion in #1611438: fieldOrderBy filters out results with empty field values:

Given the above performance regressions that this change would imply to document this as by design and keep the issue open as a non-major feature request in case someone comes up with an idea to solve this in a nice way.

I thought it'd be better to close the above bug issue and open as a feature request. But again, if you don't think this is going to be addressed, then I'm all for a won't fix.

matt2000’s picture

Related issue with an idea of a feature to solve this: #1057110: There's no way to LEFT JOIN with an EntityFieldQuery.

chx’s picture

Nope, that's not an issue to solve this, that's an issue you reopened but won't stay open for long. You can't do this on whenever you want because it'd be unbearable slow. This can only work if you don't join at all. Then you can do an order by but I am not sure how useful that is.

chx’s picture

Version: 8.0.x-dev » 7.x-dev
Issue summary: View changes

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.