开发者

where to find Drupal 7 DB schema?

开发者 https://www.devze.com 2023-03-22 02:19 出处:网络
I have this query in Drupal 6 SELECT term_data.tid AS tid, term_data.name AS term_data_name, term_data.vid AS term_data_vid,

I have this query in 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

how can I migrate that one to Drupal 7 schema? I have something like this, but it's not working

SELECT
taxonomy_term_data.tid,
taxonomy_term_data.vid,
taxonomy_term_data.name
FROM
taxonomy_term_data
LEFT JOI开发者_运维知识库N taxonomy_index ON taxonomy_term_data.tid = taxonomy_index.tid
Inner Join node ON taxonomy_index.vid = node.vid

The problem is that taxonomy_index.vid doesn't exist.

I haven't found drupal 7 database schema documentation, any idea? please Thanks


$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
}

Tip: sometimes errors will be difficult to find when stringing all those together. Optionally, you can set each one row at a time and errors seem to report better.

$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();
0

精彩评论

暂无评论...
验证码 换一张
取 消