When i develop with Drupal 8,
Using following code:

$query = \Drupal::entityQuery('taxonomy_term')
    ->condition('vid', 'addressbook_class')
    ->condition('parent', 0);

I got following error message:
Drupal\Core\Entity\Query\QueryException: 'parent' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable() (line 250 of /home/ubuntu/www/tianjin/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php)

It seems that Entity Query for Term does not support parent field.

I am not sure this is a bug or a feature request.
it will be better if I could add a condition for parent field.
otherwise I have to use db_query, or Termstorage->loadTree

Comments

g089h515r806 created an issue. See original summary.

dawehner’s picture

g089h515r806’s picture

Now the version is RC2, maybe it is not allowed to change the table name from 'taxonomy_term_hierarchy' to 'taxonomy_term__parent'.

If third module add some extra base fields which use custom storage to entity, it will be better if there is a hook for them to left join their custom storage table to base entity table. Then we can use extra base fields in entityQuery.

mikeryan’s picture

Status: Active » Closed (duplicate)

Looking at the patch in #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration, it clearly addresses this issue (there's a test doing an entity query on 'parent'), closing this issue in favor of that.