I've been writing some tests for #885014: Add pager and tablesort to EntityFieldQuery, and this example gave me a fatal error (undefined method EntityFieldQuery::orderBy in field_sql_storage.module):

$query = new EntityFieldQuery();
$query->fieldCondition($this->fields[0], 'value', 2, '>');
$query->entityOrderBy('entity_id', 'asc');
$query->execute();

What's the problem?
field_sql_storage_field_storage_query() has the following code:

  foreach ($query->entityOrder as $key => $direction) {
    $sql_field = $key == 'entity_type' ? 'fcet.type' : "$field_base_table.$key";
    $query->orderBy($sql_field, $direction);
  }
  return $query->finishQuery($select_query, $id_key);

$query is EntityFieldQuery here, we need $select_query instead.

CommentFileSizeAuthor
#3 902830.patch8.14 KBbojanz
#1 902830.patch882 bytesbojanz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Status: Active » Needs review
FileSize
882 bytes

Here's a patch. Let me know if it deserves a test, and I'll add one.

chx’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
bojanz’s picture

Status: Needs work » Needs review
FileSize
8.14 KB

Tests
I basically duplicated the existing ones for sorting, but with a fieldCondition (and modified expectations of course).
This way we have the same coverage for the two different code paths.

chx’s picture

Status: Needs review » Reviewed & tested by the community

More tests and a bugfix, that's awesome (if the tests pass).

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Needs tests

Automatically closed -- issue fixed for 2 weeks with no activity.