Here are the specific conditions that generated the error:
- User is not administrator
- Page includes a block view consisting of full nodes that use a CCK NodeReference field
- NodeAccess is enabled
Updating the following function:
function nodereference_field_formatter($field, $item, $formatter, $node) {
..
if (!isset($titles[$item['nid']])) {
if ($title = db_result(db_query(db_rewrite_sql("SELECT title FROM {node} WHERE nid=%d"), $item['nid']))) {
$titles[$item['nid']] = $title ? $title : '';
}
}
..
}
to use table aliases as follows:
if ($title = db_result(db_query(db_rewrite_sql("SELECT n.title FROM {node} n WHERE n.nid=%d"), $item['nid']))) {
removes the error message.
Comments
Comment #1
jread commentedThanks! Works for me.
Comment #2
yktdan commentedWorks for me too, but changing it to critical as I really don't like running with a patched module.
Comment #3
masipila commentedI can confirm that the problem arises in other (much simpler) scenarios as well and that the same table alias fix works for me too.
I have the following case:
- I have several content types that have nodereferences to other node types. For example, a "team" has references to "players". A "club" has references to "players" as well.
- When viewing a node of the type that has references ("team, club") the problem is triggered. It doesn't take block views for me, it's enough to view any team or club node.
- I have NodeAccess enabled as well.
The table alias fix provided works for me.
I second the request for an official release.
Comment #4
agileware commentedHere is a patch to fix this.
Rolled against dev but I imagine it applies to 1.12 too.
Comment #5
greg.harveyWorks! Thank you.
Comment #6
redhoodie commentedWorks like a charm (1.12)
Comment #7
samireez commentedWorks on CCK 5.x-1.12! Thank you!
Comment #8
TYPEX commentedIs this bug only occurring on mysql 4.1, does anyone know? Patch works great, btw
Comment #9
amanire commentedPatch worked. Please roll this into the next update!
Comment #10
greg.harvey@TYPEX The bug occurs on MySQL 5.1.47 here. But the patch fixes it, regardless.
Comment #11
longwaveDuplicate of #831056: nodereference_field_formatter: throws sql error which is also RTBC with an identical patch.
Comment #12
greg.harveyTrue, dat.