1.20.x entity.query.inc | public EntityFieldQuery::fieldOrderBy($field, $column, $direction = 'ASC') |
Orders the result set by a given field column.
If called multiple times, the query will order by each specified column in the order this method is called. Note that entities with empty field values will be excluded from the EntityFieldQuery results when using this method.
Parameters
$field: Either a field name or a field array.
$column: A column defined in the hook_field_schema() of this field. entity_id and bundle can also be used.
$direction: The direction to sort. Legal values are "ASC" and "DESC".
Return value
EntityFieldQuery: The called object.
File
- modules/
entity/ entity.query.inc, line 507 - Entity query API.
Class
- EntityFieldQuery
- Retrieves entities matching a given set of conditions.
Code
public function fieldOrderBy($field, $column, $direction = 'ASC') {
if (is_scalar($field)) {
$field_definition = field_info_field($field);
if (empty($field_definition)) {
throw new EntityFieldQueryException(t('Unknown field: @field_name', array('@field_name' => $field)));
}
$field = $field_definition;
}
// Save the index used for the new field, for later use in field storage.
$index = count($this->fields);
$this->fields[$index] = $field;
$this->order[] = array(
'type' => 'field',
'specifier' => array(
'field' => $field,
'index' => $index,
'column' => $column,
),
'direction' => $direction,
);
return $this;
}