Is there a way to use EntityStorageBase::loadByProperties() to specify that a field is either empty or not empty? I just want to check whether or not a field_date_completedhas a value set one it.

Looking to do something like $this->myEntityStorage->loadByProperties(['field_date_completed'=> notEmpty]) or $this->myEntityStorage->loadByProperties(['field_date_completed'=> isEmpty])

EDIT: Sorted out a solution using the accepted answer. Per How get empty record on date field with entityQuery?, we can do something like

$query = $this->myEntityStorage

$entity_ids = $query->execute();

1 Answer 1


Only in a narrow scope where "empty" for the field means the empty string ('') and it's stored as such in the DB.

EntityStorageBase::loadByProperties() uses a helper method, ::buildPropertyQuery(), that chains comparisons using the IN operator. As such, you can't use negation or special comparison cases (e.g. IS NULL if "empty" means NULL in the DB).

Unless you have simple string comparisons for your field, you're better off skipping ::loadByProperties() and using EntityStorageBase::getQuery() to retrieve a query object that you can customize to fit a "empty" / "not empty" query.

  • Ah that's too bad. Thanks!
    – Mrweiner
    Commented Apr 2, 2020 at 18:16
  • Do you have any examples I might be able to reference for this?
    – Mrweiner
    Commented Apr 2, 2020 at 19:55
  • Nevermind, sorted this out. Adding an example to an EDIT.
    – Mrweiner
    Commented Apr 2, 2020 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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