我在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数据库架构文档,任何想法?请 谢谢
答案 0 :(得分:0)
$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();