I have noticed that EFQ, which should return field collection item's parent entity, fails on my setup.
What I have is a field collection that can be assigned to either a node or a custom entity and I'm also using mongodb as backend.

The code is in protected function fetchHostDetails():

$query = new EntityFieldQuery();
$query->fieldCondition($this->fieldInfo(), 'revision_id', $this->revision_id);

The mongo query for this is:
db.fields_current.field_collection_item.find({revision_id: 8016363});

And that of course fails because for nodes the correct query is:
db.fields_current.node.find({revision_id: 8016363});

This can be achieved with:

$query = new EntityFieldQuery();
$query->fieldCondition($this->fieldInfo(), 'revision_id', $this->revision_id);
$query->entityCondition('entity_type', 'node');

This translates to:
db.fields_current.node.find({revision_id: 8016363});

Then it works with nodes, but not with my custom entity.

I think this is broken only when using mongodb. Has anybody else experinced the same problem?

I created a patch for this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

attekilpela’s picture

attekilpela’s picture

Issue summary: View changes
k_zoltan’s picture

Status: Active » Needs review
Chris Matthews’s picture

Version: 7.x-1.0-beta5 » 7.x-1.x-dev
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 5 year old patch in #1 to field_collection.module b/field_collection.module does not apply to the latest field_collection 7.x-1.x-dev and if still relevant needs a reroll.

field_collection-efq_host_entity-2134853-1.patch:24: trailing whitespace.
            
Checking patch field_collection.module...
error: while searching for:
      if ($this->item_id) {
        // For saved field collections, query the field data to determine the
        // right host entity.
        $query = new EntityFieldQuery();
        $query->fieldCondition($this->fieldInfo(), 'revision_id', $this->revision_id);
        if (!$this->isInUse()) {
          $query->age(FIELD_LOAD_REVISION);
        }
        $result = $query->execute();
        list($this->hostEntityType, $data) = each($result);

        if ($this->isInUse()) {

error: patch failed: field_collection.module:369
error: field_collection.module: patch does not apply