To reproduce, Drupal 7 alpha and the latest (2010 June 21) CCK 7.x-2.x: Add a userreference field (with the checkbox widget) to a node, then go to add a node of that type and check at least one user.

Drupal 7 prints the nice, bland, unexplanatory error: "The website encountered an unexpected error. Please try again later."

The error log reports:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'uid' in where clause is ambiguous: SELECT u.uid AS uid, u.name AS name, u.status AS status, r.rid AS rid FROM {users} u INNER JOIN {users_roles} r ON u.uid = r.uid WHERE (u.status IN (:db_condition_placeholder_0, :db_condition_placeholder_1)) AND (r.rid IN (:db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4)) AND (uid IN (:db_condition_placeholder_5, :db_condition_placeholder_6)) ORDER BY name ASC; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => 4 [:db_condition_placeholder_3] => 0 [:db_condition_placeholder_4] => 0 [:db_condition_placeholder_5] => 14 [:db_condition_placeholder_6] => 7 ) in _user_reference_potential_references_standard() (line 485 of /var/local/drupal/dgd7/drupal/sites/default/modules/cck/modules/user_reference/user_reference.module).

Seems PDO should be smart enough to figure this one out but i guess user_reference needs to do a little more handholding.

Comments

mlncn’s picture

Status: Active » Needs review
Issue tags: +dgd7

Here's a patch that instead of using the $user_uid_alias variable defined earlier as the output of $query->addField('u', 'uid'); explicitly uses u.uid. Not sure if this is the Drupal / PDO / DBTNG way or not, but it works.

benjamin, agaric

mlncn’s picture

With the patch attached this time.

agentrickard’s picture

Status: Needs review » Needs work

Patch fail.

agentrickard’s picture

Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new947 bytes

db_addField() does not return a table alias. Those have to be added manually.

karens’s picture

Project: Content Construction Kit (CCK) » References
Version: 7.x-2.x-dev » 7.x-1.x-dev
Component: userreference.module » Code

Move to new References module.

fgm’s picture

Component: Code » Code: user_reference

Categorizing.

danielb’s picture

Sorry didn't see this issue before.

I don't think the patch in #4 is ideal, since it relies on the field aliases being the same as the field names. It is better to explicitly supply the field name as mentioned in #1.

I have provided a patch that covers this, in this issue:
#984888: User Reference module fails validation

andypost’s picture

Status: Needs review » Closed (duplicate)