2023-04-18

以前的Query可以理解为

  1. 文章article有一个字段叫channel
  2. Channel关联到了taxonomy
  3.  查询taxonomy中的checkout_status字段值为1
// 获取一个Entity类型的Storage
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
// 获取Query
$query = $node_storage->getQuery();
$query->condition('type', 'article');
$query->condition('channel.entity:taxonomy_term.checkout_status', 1);
$ids = $query->execute();
dpm($ids);

 

再来看一个多层链接的

  1. 文章article中有一个字段叫channel
  2. channel关联了taxonomy
  3. channel中一个字段叫车辆类型:vehicle_type
  4. vehicle_type又关联了taxonomy
  5. vehicle_type的名字叫汽车运输的
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $node_storage->getQuery();
$query->condition('type', 'article');
$query->condition('channel.entity:taxonomy_term.vehicle_type.entity:taxonomy_term.name', '汽车运输');
$ids = $query->execute();
dpm($ids);

 

标签: Drupal9 Drupal