My user table has an init field in it, it maybe empty or not. I want to find all rows that are not empty I tried

  $query = new EntityFieldQuery();
    ->entityCondition('entity_type', 'user')

function mymodule_role_filter_alter(QueryAlterableInterface $query) {
  $query->innerJoin('users_roles', 'ur', 'users.uid = ur.uid');  
  $query->innerJoin('role', 'r', 'r.rid = ur.rid');
  $query->condition('r.name', ['administrator', 'contributor', 'publisher'], 'IN');
  $query-> isNotNull(ur.init); // I ALSO TRIED a != '' condition

What I am doing now that works is:

  $results = $query->execute();

  $users_node_list = entity_load('user', array_keys($results['user']));

  $return_results = array();

  foreach ($users_node_list as $key => $value) {
        if ($value->init != ''){

but that is post query.

and read https://www.drupal.org/node/1157006

but this is not working (I don't get any results when I add this)


  • 1
    This question is not complete. Please show your entire query, so we can see better what is going on. Also look at post #4 of your linked page. That shows the trick for performing a join using an earlier added tag. – Neograph734 Feb 15 '17 at 22:49
  • added needed code – Quantico Feb 16 '17 at 3:06
  • And how do you process to results of the query? The more complete you are, the better we can help. – Neograph734 Feb 16 '17 at 6:49
  • isn't this the entity load part? – Quantico Feb 16 '17 at 13:57
  • 1
    I was referring to the part where you execute the query and process the results. – Neograph734 Feb 16 '17 at 15:00

You can do this by

$query->condition('field', '', '<>');

See: https://api.drupal.org/api/drupal/includes%21database%21select.inc/function/SelectQuery%3A%3Acondition/7.x

If this doesn't answer your question you need to. Be more specific.

| improve this answer | |
  • what is the <> operator I cannot find any info about it – Quantico Feb 16 '17 at 13:58
  • It is the non equal operator. See this SO post for more information. – Neograph734 Feb 16 '17 at 16:58

In drupal 8, you can use the exists function like so :

$query = \Drupal::entityQuery('node');    
$results = $query->execute;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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