EntityFieldQuery Extra Fields

Component ID

1563472

Component name

EntityFieldQuery Extra Fields

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

9515

Component created

Component changed

Component body

Warning : This module abuses EntityFieldQuery to return data from your database. It does not work with entities or any modules that build on them.

It allows you to use addField within an EntityFieldQueryExtraFields object (extends EntityFieldQuery objects). Initially EntityFieldQuery only gives you back the entity id, bundle and entity type. This module adds an extra layer on top of that without doing some extra entity_loads! Important if you want to work with massive amounts of data and you want to reduce the sql queries. Since EFQ already queries the database for this information, why not alter that query to also give you some additional fields. This means that not a single extra query will be performed to get that data.

A word of caution, if you rely on some post-formatting/post-loading that happens in entity_load or similar functions, this module won't take care of that. You have to ensure the validity of the retrieved data yourselves.

Example

Fetching the node title

$query = new EntityFieldQueryExtraFields();
  $result = $query->entityCondition('entity_type', 'node')
  ->propertyCondition('type', 'my_bundle_type')
  ->propertyCondition('status', 1)
  ->addExtraField('field_myfield', value', value')
  ->addExtraField('field_mynodereffield', nid', nid')
  ->addExtraField('', 'title', 'title', 'node')
  ->fieldCondition('field_myfield', 'value', 'some_value_to_filter_on', '=')
  ->execute();

Possible combinations :
addExtraField($field_name, $column, $column_alias = NULL, $table = NULL)

field_name

Specify from which field the extra field should come. If it is from a base table, leave it empty and fill in the table argument

column

Specify the name of the column,

column_alias

Specify the alias of the column,

table

Optionally, add something like node or user here (the base table),