As suspected in #1518314: EntityFieldQuery should ignore bundle filter setting if there is no key for the entity, I've confirmed that update 7001 leaves the field_config of old User Reference fields corrupt. Specifically, it leaves behind a target_bundle in the handler settings.

That in turn causes Autocomplete to break when adding new field content as Administrator, and likely other issues too.

The attached patch contains an entityreference_update_7002 which fixes the corrupt fields by removing the target_bundle.

While working on this, I investigated another discrepancy between fields created before and after 7.x-1.0-beta3.

It looks like fields created uing the latest code are setting a foreign key for user reference.target_id that referencies node(nid).

When I tried to run same the foreign key generation code (from hook_schema) in my update, the code exited immediately because it failed the '''if (isset($base_tables[$entity_type])) {''' test.

If that's correct, then it appears that hook_schema() is called as the field settings form is first loaded, and then the foreign key returned with the deafult target type of 'node' are used regardless of the actual target type selected. I think that would result in errors (in PostGRES anyway, or maybe if you converted all your tables to InnoDB). ie. If you tried to enter a uid as a user reference that was not the same uid as a nid of an existing node, then the insert would fail at the database level. Most of the time, the uid and nid would probably both exist and no one would notice. Does that sound right? And if so should I open an issue for it?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tomogden’s picture

Status: Needs review » Needs work

This update returns errors on my system.

From drush:

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'field_photo_target_id' at row 6

From browser (/update.php):

Failed: PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'field_photo_target_id' at row 6: ALTER TABLE {field_data_field_photo} CHANGE `field_photo_target_id` `field_photo_target_id` INT unsigned NOT NULL COMMENT 'The id of the target entity.'; Array ( ) in db_change_field() (line 2985 of /var/www/html/includes/database/database.inc).