2

I added a required field in a Job type node later. So existing nodes don't have that particular field value. I want to include all such field values. But how can I do it?

Here is query sample:

$query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', array('central_government_vacancy','psu_vacancy','state_government_vacancy'))
    ->propertyCondition('status', 1)
    -> fieldCondition('field__expired_processed', 'value', 'NULL', '=')  //I'm looking for this field
    ->fieldCondition('field_last_date_of_application', 'value', $date, '<=');

In the above code I want to find nodes having uninitialized field values : field_expired_processed.

!=, or using NULL to compare does not seem to work.

0

1 Answer 1

2

If you look on the fieldCondition documentation page you will see the following warning:

Note that entities with empty field values will be excluded from the EntityFieldQuery results when using this method.

Checking whether a field exists or not has been added to entityFieldQuery in Drupal 8, but unfortunately won't be backported to Drupal 7.

This means you must use standard SelectQuery in order to achieve this. You must join the table which contains your data, and check whether the fiels IS NULL. It would be something like:

$q = db_select('node', 'n');
$q->condition('n.type', 'central_government_vacancy', '=')
->addJoin('LEFT', 'field_data_field_expired_processed', 'f')
->isNull('f.value');
$r = $q->execute();
2
  • It is possible with an EntityFieldQuery but you need to implement hook_query_TAG_alter() to do so
    – Clive
    Commented Mar 11, 2013 at 14:29
  • For Drupal 7 as workaround, see drupal.org/node/1157006#comment-7634027
    – kenorb
    Commented Oct 4, 2013 at 11:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.