Problem/Motivation

Given an entity reference field in which the Target Type is "Node", Mode is "Simple", and Target Bundles are left unchecked (resulting in all being available), running Devel Generate's content generation function results in an error. Here is an excerpt from an example message for a "related node" entityreference field when running Devel Generate:

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'page' for column 'field_related_nodes_target_id' at row 1: INSERT INTO {field_data_field_related_nodes} [...]

Proposed resolution

I have found the issue to be in entityreference.devel_generate.inc:_entityreference_devel_generate()'s handling of the results of a call to getReferencableEntities(). The result of a call to getReferencableEntities() is and array keyed by the entity type and then by entity ID. _entityreference_devel_generate() appears to be coded under the assumption that the results are simply keyed by the entity ID, which they are not.

Remaining tasks

The solution is coded and ready for review. I have only tested this on an entity reference field in which the Target Type is "Node", Mode is "Simple", and Target Bundles are all left unchecked. Other uses of entity reference and Devel Generate need to be tested.

Comments

benkoren’s picture

Status: Active » Needs review
benkoren’s picture

I was mistaken in my previous patch. Attached is the patch that should fix the issue correctly.

Status: Needs review » Needs work

The last submitted patch, entityreference-devel-generate-fix.diff-2.diff, failed testing.

benkoren’s picture

benkoren’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, entityreference-devel-generate-fix.diff-3.diff, failed testing.

benjifisher’s picture

Status: Needs work » Closed (duplicate)

This is a duplicate of #1852112: Invalid field value with devel_generate.

I have no idea why the original patch above passed automatic testing. The patch from the other issue was committed on January 1.

I like the patch here better than the one that was adopted. It seems like an odd use of a loop:

    foreach ($referencable_entity as $type => $eids) {
      $object_field['target_id'] = array_rand($eids);
    }