After I installed this module, all my stories are in reverse order (show very first post on top). I'm using PostgreSQL if that helps. Any ideas how I can fix this?
After I installed this module, all my stories are in reverse order (show very first post on top). I'm using PostgreSQL if that helps. Any ideas how I can fix this?
Comments
Comment #1
AndyColson commentedOk, Its not only this module... any of the node access modules (Content Access, taxonomy_access and tac_lite) have the same problem... so maybe its a problem in core and not these modules?
-Andy
Comment #2
AndyColson commentedOk, more info...
I ran it twice, with devel enabled, to see the query's run.
Normally this is the sql executed:
But when I enable one of the Content Access modules, this is the sql:
Note the ORDER BY changed. I tracked to node.module line 2421, which shows this:
$result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10));So is the db_rewrite_sql changing the order by too?
The hook method does not seem to rewrite the orderby, here is the code:
function node_db_rewrite_sql($query, $primary_table, $primary_field) {if ($primary_field == 'nid' && !node_access_view_all_nodes()) {
$return['join'] = _node_access_join_sql($primary_table);
$return['where'] = _node_access_where_sql();
$return['distinct'] = 1;
return $return;
}
}
If I remove the distinct line ($return['distinct'] = 1;) it seems to work correctly.
-Andy
Comment #3
kazi-1 commentedI am using version 4 (PostgreSQL database), and just upgraded to 4.7.8. After doing so, I had the same problem. Although the line numbers are different, the patch mentioned above fixed the problem, but I didn't like the idea of just removing the DISTINCT directive, so I dug into the file "database.pgsql.inc" (within the "includes" directory). I found the function to automatically create DISTINCT queries: db_distinct_field(). The function looks like this (starting at line 376 in my version):
Notice that the ORDER BY is indeed getting re-written... although I'm not sure why this is necessary. I commented out the line
$query = preg_replace('/(ORDER BY )(?!'.$table.'\.'.$field.')/', '\1'."$table.$field, ", $query);and it fixed the problem. I'm still not sure what the "correct" fix would be... but this worked for me.
Hope this helps!
-- kazi
Comment #4
kazi-1 commentedScratch that... I just figured out why ORDER BY has to be changed... Not doing so results in this error:
So the DISTINCT directive is on nid, so nid must be included in the first ORDER BY... but that is exactly what we _don't_ want to do, since it breaks the sort order. I'm back to Andy's original fix: comment out the
$return['distinct'] = 1;line in node.module.Comment #5
rbroberts commentedThis is still true in 5.5. I upgraded last night from an older 4.7 to 5.5 do deal with various security issues. By far the most painful part of the process was finding out why my front page had entries sorted in chronological order instead of reverse. I tried uninstalling some modules, I tries installing the Views modules, I had already edited some queries in database.pgsql.inc, and none of it had any affect.
Andy's fix of commenting out
$return['distinct'] = 1;worked fine. Here's some information from my status page:
Comment #6
dpearcefl commentedDue to the age of the last comment on this issue and due to the fact that D5 is no longer supported, I am closing this issue.