When I create a nodereference as a select box, I get the following message when I try to create a new record:

user warning: Unknown table 'n' in field list query: SELECT DISTINCT(n.nid), title, type FROM node WHERE type = 'blog' OR type = 'book' OR type = 'event' OR type = 'page' OR type = 'story' ORDER BY title, type in drupal_path\includes\database.mysql.inc on line 118.

The query seems to be missing the "n" alias after "FROM node". I tried to figure out where in the code this is coming from so I could just plug this change in and see what happened, but couldn't find it. The list of types matches the types I selected to use for nodereference field, the list changes when I change those values to match whatever nodes I select for the noderefence field, and the error only shows up when I try to add a new record using CCK, so it has to be generated somewhere in the CCK code.

Comments

karens’s picture

After reporting this I found the place in the code that needs to be fixed. It is line 365 in nodereference.module.

Change that line from:

$result = db_query(db_rewrite_sql("SELECT nid, title, type FROM {node} WHERE ". $related_clause ." ORDER BY title, type"));

to

$result = db_query(db_rewrite_sql("SELECT nid, title, type FROM {node} n WHERE ". $related_clause ." ORDER BY title, type"));

and the select box appears correctly.

jonbob’s picture

Status: Active » Fixed

Cleaned up the queries in general by adding table aliases, which should fix this.

Anonymous’s picture

Status: Fixed » Closed (fixed)