Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am trying to perform a query as listed below (notice the check for NULL)

$query = db_select('node', 'n');
/* add fields and joins... */
$query->condition(db_or()
      ->condition(db_and()
                  ->condition('join_alias1.field_date_unassigned_value', NULL, 'IS')
                  ->condition('join_alias2.field_date_assigned_value', $end_date, '<='))
      ->condition(db_and()
                  ->condition('join_alias1.field_date_unassigned_value', $start_date, '>=')
                  ->condition('join_alias2.field_date_assigned_or_submitted_value', $end_date, '<=')));

I am aware that Drupal expects Null values to be checked like

$query->isNull('myfield');

But I don't understand how to perform a query like I listed above while using $query->isNull().

Any ideas? Thanks

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can use isNull() in the db_and() condition, it'll work just fine:

$query->condition(db_or()
  ->condition(db_and()
    ->isNull('join_alias1.field_date_unassigned_value')
    ->condition('join_alias2.field_date_assigned_value', $end_date, '<=')
  )
  ->condition(db_and()
    ->condition('join_alias1.field_date_unassigned_value', $start_date, '>=')
    ->condition('join_alias2.field_date_assigned_or_submitted_value', $end_date, '<=')
  )
);
share|improve this answer
    
thank you! sorry, don't have the rep to up vote. –  pymarco Jan 23 '14 at 15:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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