Let's say you create a simple node view with "Node: Title" and "Taxonomy: Term" fields.
The query is then:
SELECT node.title AS node_title,
term_data.name AS term_data_name,
term_data.vid AS term_data_vid,
term_data.tid AS term_data_tid
FROM node node
LEFT JOIN term_node term_node ON node.vid = term_node.vid
LEFT JOIN term_data term_data ON term_node.tid = term_data.tid
When you want to limit terms, you may then use "Taxonomy: Term" filter, that will add to the query:
WHERE term_node.tid IN (TID1, TID2)
This makes sense.
But then you use "Taxonomy: Term ID (with depth)", this adds:
WHERE node.vid IN (
SELECT tn.vid FROM term_node tn
LEFT JOIN term_hierarchy th ON th.tid = tn.tid
LEFT JOIN term_hierarchy th1 ON th.parent = th1.tid
WHERE tn.tid = TID
OR th1.tid = TID
)
When you would expect something like:
WHERE term_node.tid IN (
SELECT th.tid FROM term_hierarchy th
LEFT JOIN term_hierarchy th1 ON th.parent = th1.tid
WHERE th.tid = TID
OR th1.tid = TID
)
So it seems that a "Taxonomy: Term ID (with depth)" is missing.
And shouldn't the current "Taxonomy: Term ID (with depth)" be named differently?
Or maybe I'm missing something...
Comments
Comment #1
anrikun commentedComment #2
anrikun commentedDeleted.
Comment #3
anrikun commentedReverting.
Comment #4
anrikun commentedAttached is a quick written module that adds the missing filter handler described in this issue, and the corresponding argument handler.
It would be great if maintainers could have a look at it.
I am sure the way the module is written could be improved, without using a subquery, but I don't really understand join helpers as they are not documented.
If maintainers are interested in this feature, I am OK to write a patch but I would need some info about the undocumented helpers of the API.
Let me know.
Comment #5
anrikun commented#903438: Let taxonomy views have a Term ID with depth as well is of interest too.
Comment #6
kenorb commentedMarked as duplicate: #1093680: Filter terms by depth inside of "Taxonomy view"
Comment #7
TimelessDomain commented#4 looks good. This should be added directly into the views module.
As D7 represents the move towards entities, views should plan on allowing the same types of arguments and filters on all entities. Taxonomy: Term ID (with depth) in taxonomy views is a good step towards this. Next Taxonomy: Term ID (with depth) on users & entities (may already be available?).
Comment #8
Anonymous (not verified) commented(cross posted: #903438: Let taxonomy views have a Term ID with depth as well)
The behavior of "Taxonomy Term ID (with depth)" still exists in Views 3, but it is now called something different. Instead look for, "Content: Has Taxonomy Term ID (With Depth)". It's in the content not taxonomy section of contextual filters.
In my use case, in order to select nodes with the child of a given term argument, I had to do the following:
1. Create a term relationship (named it term).
2. Added the term ID with depth filter.
3. Views automatically also created a contextual filter for Term using the relationship created earlier. I deleted this.
Comment #9
mustanggb commented