Download & Extend

EntityFieldQuery::execute documentation - return value example doesn't work if query result is empty

Project:Drupal core
Version:7.x-dev
Component:documentation
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:needs backport to D7, Novice

Issue Summary

API page: http://api.drupal.org/api/drupal/includes--entity.inc/function/EntityFie...

Dear all,

The documentation of 'Return Value' states:

<?php
    $result
= $query->execute();
   
$entities = entity_load($my_type, array_keys($result[$my_type]));
?>

It seems that this only works when the result is nonempty. Otherwise $result[$my_type] causes an error message Notice: Undefined index: model in .... To fix this, you must explicitly check for empty results, not so elegant, but necessary it seems.

Kaspar

Comments

#1

Title:Documentation problem with EntityFieldQuery::execute» EntityFieldQuery::execute documentation - return value example doesn't work if query result is empty
Version:7.x-dev» 8.x-dev

Thanks for reporting this! I think a novice patch contributor could probably fix this.
It appears that it needs fixing in Drupal 8 first:
http://api.drupal.org/api/drupal/core--modules--entity--entity.query.inc...

I'm not sure why the Drupal 8 and 7 versions of this method don't link to each other... probably because the file name has changed. Anyway, that's a separate issue, which I'll file in the API module.

#2

For anyone interested, here's the issue about the methods not linking to each other:
#1429314: Other versions linking between branches on methods pages seems to be broken

#3

Status:active» needs review

I've added "The entity type will only exist in the outer array if results were found." to the return description and an if statement has been added to the sample code.

I've also adjusted the line wrap on the first line as the text was wrapping too early - I can remove this change if it shouldn't be included.

AttachmentSizeStatusTest resultOperations
1427098.patch1.86 KBIdlePASSED: [[SimpleTest]]: [MySQL] 34,467 pass(es).View details

#4

Status:needs review» reviewed & tested by the community

Looks good, thanks!

#5

Version:8.x-dev» 7.x-dev

Committed to 8.x. Thanks. Moving to 7.x.

#6

Status:reviewed & tested by the community» needs review

D7 version.

AttachmentSizeStatusTest resultOperations
1427098-d7.patch1.8 KBIgnored: Check issue status.NoneNone

#7

Renamed for testing.

AttachmentSizeStatusTest resultOperations
1427098-d7-version.patch1.8 KBIdlePASSED: [[SimpleTest]]: [MySQL] 37,886 pass(es).View details

#8

Status:needs review» needs work

This patch is not the same as th D8 patch. It has a typo "In most this cases this...".

#9

I knew there was something else I fixed in the D8 version. This one should be correct.

AttachmentSizeStatusTest resultOperations
1427098-d7-version-2.patch1.8 KBIdlePASSED: [[SimpleTest]]: [MySQL] 37,913 pass(es).View details

#10

Status:needs work» needs review

Change status.

#11

Status:needs review» reviewed & tested by the community

Thanks -- now the patches are the same (except context). :)

#12

Status:reviewed & tested by the community» fixed

Committed to 7.x. My first commit! :)

#13

YAYYY! :D Welcome, Jennifer!!

#14

Status:fixed» closed (fixed)

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

nobody click here