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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 843608-user-reference-query.patch | 947 bytes | agentrickard |
| #2 | cck-user_reference-ambiguous-uid-pdo-exception-843608.patch | 0 bytes | mlncn |
Comments
Comment #1
mlncn commentedHere'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
Comment #2
mlncn commentedWith the patch attached this time.
Comment #3
agentrickardPatch fail.
Comment #4
agentrickarddb_addField() does not return a table alias. Those have to be added manually.
Comment #5
karens commentedMove to new References module.
Comment #6
fgmCategorizing.
Comment #7
danielb commentedSorry 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
Comment #8
andypostRework of this in #1004212: [release blocker] Add content crashes with User reference field