This is my first post. It is possible that I am posting at the wrong place…
First of all: thank you for the great module!
Just wanted to mention the problem and solution in case it might be useful for someone else.
I was creating a view and selected “Random” as sort criteria. I noticed that the view came out with duplicate records. After doing some code debugging I found the following.
The query was constructed with “rand() as random_order” added as a field, then the query was using “order by random_order” . I fixed the problem by removing extra field and ordering records by the function itself: “order by “rand()”.
To do so, I modified add_orderby function in views_quiery.inc. Instead of:
$this->add_field($f, $table, $as);
$this->orderby[] = "$as $order";
I now have:
if ($table){
$this->add_field($f, $table, $as);
$this->orderby[] = "$as $order";
}else{
$this->orderby[] = "$f $order";
}
Hope this post can be useful.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | views-6.x-2.12-random-sort-dedup.patch | 636 bytes | john franklin |
Comments
Comment #1
esmerel commentedThis might be related to the core 'distinct' issue. No fixes are planned for the 1.x line of views.
Comment #2
jmseigneur commentedWe have had the same problem. Duplicate records in Views after setting the View order to random and are trying the fix given above in the description.
Comment #3
andriy commentedthe same problem is in 6.x-2.11 version, here is my solution without modifying views core code, insert it into any custom module, do not forget to replace 'yourmodule' with real name:
in order to fix core code, views_handler_sort_random.inc should be changed to:
Comment #4
dawehnerPlease please please don't hijack such old issues. Thanks!
Comment #5
john franklin commentedIt's a real head scratcher, that's for sure. You don't need to save the integer in the $_SESSION as in #3 above. Choosing a new random integer to pass to RAND() will do. The attached patch should not work, but does on Views 6.x-2.12.