【问题标题】:where to find Drupal 7 DB schema?在哪里可以找到 Drupal 7 DB 模式?
【发布时间】:2011-07-22 16:06:56
【问题描述】:

我在 Drupal 6 中有这个查询

SELECT term_data.tid AS tid,
   term_data.name AS term_data_name,
   term_data.vid AS term_data_vid,
   term_data.weight AS term_data_weight
 FROM term_data term_data 
 LEFT JOIN term_node term_node ON term_data.tid = term_node.tid
 INNER JOIN node node_term_node ON term_node.vid = node_term_node.vid

如何将那个迁移到 Drupal 7 架构?我有这样的东西,但它不起作用

SELECT
taxonomy_term_data.tid,
taxonomy_term_data.vid,
taxonomy_term_data.name
FROM
taxonomy_term_data
LEFT JOIN taxonomy_index ON taxonomy_term_data.tid = taxonomy_index.tid
Inner Join node ON taxonomy_index.vid = node.vid

问题是 taxonomy_index.vid 不存在。

我还没有找到 drupal 7 数据库模式文档,知道吗?请 谢谢

【问题讨论】:

  • 您不能查看数据库并检查有关如何构造查询的表吗?
  • 您要查找的列可能在taxonomy_vocabulary.vid。你到底想完成什么?
  • 我想完成上面显示的 Drupal 6 查询中正在完成的工作:它是一个分类列表。

标签: mysql drupal-6 drupal-7


【解决方案1】:
$terms = db_select('term_data', 'td')
  ->fields('td', array('tid', 'name', 'vid', 'weight'))
  ->leftJoin('term_node', 'tn', 'td.tid = tn.tid')
  ->join('node', 'n', 'tn.vid = n.vid')
  ->execute();

foreach ($terms as $term) {
  // do something with $term
}

提示:有时将所有错误串在一起时很难发现错误。或者,您可以一次设置每一行,错误似乎报告得更好。

$query = db_select('term_data', 'td');
$query->fields('td', array('tid', 'name', 'vid', 'weight'));
$query->leftJoin('term_node', 'tn', 'td.tid = tn.tid');
$query->join('node', 'n', 'tn.vid = n.vid');
$terms = $query->execute();

【讨论】:

  • Coder1 非常感谢您抽出宝贵的时间,我很感激。确实,您的代码在 Drupal 6 中运行良好,但我认为您不理解我的问题,因为我在询问如何将该 Drupal 6 查询迁移到 Drupal 7。表 term_node 在 Drupal 7 架构中不存在了。还是谢谢
猜你喜欢
  • 1970-01-01
  • 2013-09-16
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 1970-01-01
  • 1970-01-01
  • 2021-12-31
  • 2021-07-05
相关资源
最近更新 更多