When using the view type "Lineage: Nested taxonomy summary", term_lineage_depth and term_lineage_lineage are added to the SELECT query. This causes a query which would otherwise be distinct to return multiple rows per node. For instance, if your view takes a taxonomy term ID as an argument.
Here's the query my view is running:
SELECT DISTINCT(node.nid), term_lineage.depth AS term_lineage_depth, term_lineage.lineage AS term_lineage_lineage FROM node node LEFT JOIN term_node term_node ON node.nid = term_node.nid LEFT JOIN term_data term_data ON term_node.tid = term_data.tid LEFT JOIN term_node term_node2 ON node.nid = term_node2.nid LEFT JOIN term_lineage term_lineage ON term_node.tid = term_lineage.tid WHERE (node.status = '1') AND (term_data.vid = '2') AND ((term_node2.tid = '1002')) ORDER BY node.sticky DESC, node.title ASC, term_lineage.lineage ASC LIMIT 0, 999
And here's the result:
+-----+--------------------+------------------------+
| nid | term_lineage_depth | term_lineage_lineage |
+-----+--------------------+------------------------+
| 1 | 1 | 10Thingies\n10nested 2\n |
| 1 | 0 | 10Widgets\n |
+-----+--------------------+------------------------+
As you can see, node 1 is returned twice because it is tagged with two terms.
Can anything be done about this? If you give me a hint I may be able to come up with a patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 90161.patch.txt | 1.32 KB | Dave Cohen |
Comments
Comment #1
Dave Cohen commentedI solved my problem by adding a check to views_bonus_views_query_alter, running it's code only if $summary is TRUE.
Note the attached patch includes another patch I found on drupal.org. THe only change relavant to this issue is the very last one.
Note that this function also adds an orderby clause. This is nice, but not effective if the view already has an orderby. For instance, my view wants to order the last page by node.sticky and node.title. Because those are already in the query, appending the lineage orderby does very little. It would be nice if that line could prepend the lineage sort.
Comment #2
merlinofchaos commentedCommitted, though I haven't played with this view a whole lot.
Comment #3
(not verified) commented