1

I'm trying to figure out if deleted entities are automatically excluded from entity queries. IE, if I did:

$num = \Drupal::entityQuery('my_entity')->count()->execute();

Would the number of entities found go down if I deleted one through the ui? How could I include/exclude deleted entities in this query?

2
  • The number should go down. Why did you ask, is there an issue?
    – 4uk4
    Sep 19, 2016 at 16:39
  • Because I wasn't sure, and when I googled it no answer came up. If I managed to come up with a definitive answer before anyone else was going to answer it myself. Sep 19, 2016 at 18:48

1 Answer 1

2

Deleted entities are not excluded because they are gone. They can't be excluded nor included as they do no longer exist in the database.

So they can also not be counted anymore.

This might change during 8.x, as there is work going on for archiving/putting them into trash instead of actually deleting. The details of that and how that affects entity queries are still being discussed.

2
  • To add to that, you could just add the condition of 'status' as 1, or if it is a custom entity, the property that indicates the content is in an "active" viewable state. Then it would be without question - and if in the future core changes to archive and not delete content, it is potentially future proofed from change.
    – Kevin
    Sep 19, 2016 at 18:33
  • Backwards compatibility will be preserved thought the 8.x cycle by definition, so presumably any entity query syntax that currently does not load deleted entities will continue to work that way during 8.x
    – Jonathan
    Sep 20, 2016 at 10:58

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.