I've created a view for taxonomy terms with node count.

SELECT taxonomy_term_data.name AS taxonomy_term_data_name, taxonomy_term_data.vid AS taxonomy_term_data_vid, taxonomy_term_data.tid AS tid, taxonomy_vocabulary.machine_name AS taxonomy_vocabulary_machine_name, COUNT(node_taxonomy_index.nid) AS node_taxonomy_index_nid
FROM 
{taxonomy_term_data} taxonomy_term_data
LEFT JOIN {taxonomy_index} taxonomy_index ON taxonomy_term_data.tid = taxonomy_index.tid
LEFT JOIN {node} node_taxonomy_index ON taxonomy_index.nid = node_taxonomy_index.nid
LEFT JOIN {taxonomy_vocabulary} taxonomy_vocabulary ON taxonomy_term_data.vid = taxonomy_vocabulary.vid
GROUP BY taxonomy_term_data_name, taxonomy_term_data_vid, <strong>tid</strong>, taxonomy_vocabulary_machine_name

Comments

chi’s picture

I am using drupal 7 (sqlite 3.3.7) with views-7.x-3.x-beta3.
It looks as tid column is realy ambiguous. But it works well on my localhost (sqlite 3.7.2).

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Can you please share an export of the view?

This would really help to reproduce the problem/fix the problem.

chi’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new9.15 KB
Letharion’s picture

Status: Needs review » Active
merlinofchaos’s picture

Status: Active » Needs review
StatusFileSize
new5.69 KB

Here's an initial patch to attempt to make sure that relationships are valid. The code is generic enough that this can work for things that aren't just taxonmy, and it can also have the beneficial effect of allowing me to get rid of some old implicit relationships that I don't like. In fact, we might be able to make relationships a less advanced concept with fewer implicit relationships, since those really confuse things.

Anyway, this patch isn't fully ready, I don't think, because we need to identify all the tables that 'node' got removed as a possible base and add it as a default relationship. But other than that I think it's in good shape, and could use some testing.

merlinofchaos’s picture

Status: Needs review » Fixed
merlinofchaos’s picture

Committed this for all the taxonomy tables that have been updated.

Something to consider for the future: Getting rid of the implicit relationships from 'node' to 'user' and 'comment' and require them to be explicit, and add this to handle updating old views to fill in the explicit relationship automatically.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.