Attached is a patch that modifies the set_distinct() method to take an optional parameter, so one could also set it to false. Furthermore it doesn't apply DISTINCT two times and is imho a cleaner solution than the solution before using substr (http://drupal.org/node/110462)
So now the DISTINCT will be added to the query when the query is generated in query().
I also changed it to keep the count_field. Before views was overwriting the count_field if one calls set_distinct().
Further if distinct is set, views should add all fields to the select even if it is a count query. Otherwise there might be a different result (count). This issue is also addressed with this patch.
This patch would allow me to fix an issue of views fusion:
It produces invalid queries if the fused view contains a DISTINCT. This patch introduces the necessary API to fix it within views fusion.
The patch applies also to views 4.7.x.
Comment | File | Size | Author |
---|---|---|---|
#1 | views_distinct_5_0.patch | 1.48 KB | fago |
views_distinct_5.patch | 1.84 KB | fago | |
Comments
Comment #1
fagosry, the last patch was broken, please ignore it..
>Further if distinct is set, views should add all fields to the select even if it is a count query. Otherwise there might be a different result (count). This issue is also addressed with this patch.
I've removed that part of the patch, because I wasn't able to get it going - perhaps this is why the count_field exists ;)
So attached is the fixed patch, which does only what's the title says:
Improve set_distinct() by moving the query change to the query generating phase.
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedNot only is this an excellent patch on its own, it fixes another semi-related bug completely on its own. Double points for this one. Thanks!!!
Comment #3
(not verified) CreditAttribution: commentedComment #4
siaiweb CreditAttribution: siaiweb commentedI tried to apply the patch, but views (1.5 / drupal 5.1) returns an error for any request... Seems like i'm too dumb to copy/paste some code lines...
Can anyone upload the updated views_query.inc ?? Thx in advance....
Comment #5
siaiweb CreditAttribution: siaiweb commentedOookay, i figured it out by myself, but i still have this bug: when i make a month/year archive using views, i still have an error while counting the free-tagged nodes: every node is counted as many times as there are taxonomy terms attached to the node. For example, for the month february, i only have one post, tagged with four terms. But the archive list returns the following result:
february, 2007 (4)
and when i click on it, no duplicates anymore (thanks to the patch). Any ideas?