如何在 Drupal 8 中执行查询?

问题描述

我想要类似的东西:SELECT tid,name FROM taxonomy_term_field_data where vid = 'copyright' and tid not in (SELECT disTINCT field_term_copyright_target_id FROM media__field_term_copyright);

我的代码

<?PHP

$query_unused_taxonomy = "
 SELECT
    tid,name FROM {taxonomy_term_field_data}
 WHERE
    vid = 'copyright'
 AND
    tid
 NOT IN
    (SELECT disTINCT field_term_copyright_target_id FROM {media__field_term_copyright});";

 $database = \Drupal::database();
 $query = $database->query($query_unused_taxonomy);

 if ($result = $query->execute()) {
     foreach ($result as $tid) {
         $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
         $entities = $term->loadMultiple($tid);
         $term->delete($entities);
      }
   return ('Delete successful');
 }
 else {
     throw new UpdateException('Query Failed to execute.');
   }

当我运行此代码时,foreach 循环不会加载任何结果。

我能做什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)