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.

CommentFileSizeAuthor
#4 cck-ambiguous_column-865354-4.patch595 bytesagileware

Comments

jread’s picture

Thanks! Works for me.

yktdan’s picture

Priority: Normal » Critical

Works for me too, but changing it to critical as I really don't like running with a patched module.

masipila’s picture

I 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.

agileware’s picture

Status: Active » Needs review
StatusFileSize
new595 bytes

Here is a patch to fix this.

Rolled against dev but I imagine it applies to 1.12 too.

greg.harvey’s picture

Status: Needs review » Reviewed & tested by the community

Works! Thank you.

redhoodie’s picture

Works like a charm (1.12)

samireez’s picture

Works on CCK 5.x-1.12! Thank you!

TYPEX’s picture

Is this bug only occurring on mysql 4.1, does anyone know? Patch works great, btw

amanire’s picture

Patch worked. Please roll this into the next update!

greg.harvey’s picture

@TYPEX The bug occurs on MySQL 5.1.47 here. But the patch fixes it, regardless.

longwave’s picture

Duplicate of #831056: nodereference_field_formatter: throws sql error which is also RTBC with an identical patch.

greg.harvey’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

True, dat.