When using mongodb field storage the field_has_data() seems to always return true, as the logic only selects the on the collection and doesn't determine if the field actually exists in the index.

Patch to follow.

Comments

camidoo’s picture

StatusFileSize
new1.07 KB

Currently when determining if the EFQ in question is a 'has_data' query, the resulting collection is queried without checking the existence of the field in question, which results in a result that is always TRUE.

  if (mongodb_collection('fields_current', $entity_type)->find()->limit(1)->count(TRUE)) {
    return TRUE;  
  }

changing this to check for the existence of the field (meaning there is data present) fixes the issue:

  if (mongodb_collection('fields_current', $entity_type)->find(array($field['field_name'] => array('$exists' => TRUE)))->limit(1)->count(TRUE)) {
    return TRUE;
  }
misc’s picture

Great, I started to work on a patch for this problem, but got problem with my solution, this seems more straightforward - it will check it later today.

camidoo’s picture

Additionally it is looping through bundles and omitting that information in the query as well, should the bundle / type be included as well?

          foreach ($field['bundles'] as $entity_type => $data) {
            foreach($data as $bundle_name) {
              if (mongodb_collection('fields_current', $entity_type)->find(array($field['field_name'] => array('$exists' => TRUE), 'type' => $bundle_name))->limit(1)->count(TRUE)) {
                return TRUE;
              }
            }
          }
camidoo’s picture

StatusFileSize
new1.26 KB

Patch for #3

misc’s picture

Status: Active » Reviewed & tested by the community

#3: Yes I think that bundle/type should be included.

Booth patches reviewed and committed to latest dev.

Thanks for you contribution, field_has_data has been a problem for a while now.

misc’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.