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

Files: 
CommentFileSizeAuthor
#9 1427098-d7-version-2.patch1.8 KBchris.leversuch
PASSED: [[SimpleTest]]: [MySQL] 37,913 pass(es).
[ View ]
#7 1427098-d7-version.patch1.8 KBchris.leversuch
PASSED: [[SimpleTest]]: [MySQL] 37,886 pass(es).
[ View ]
#6 1427098-d7.patch1.8 KBchris.leversuch
#3 1427098.patch1.86 KBchris.leversuch
PASSED: [[SimpleTest]]: [MySQL] 34,467 pass(es).
[ View ]

Comments

Title:Documentation problem with EntityFieldQuery::executeEntityFieldQuery::execute documentation - return value example doesn't work if query result is empty
Version:7.x-dev» 8.x-dev
Issue tags:+Novice, +needs backport to D7

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.

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

Status:Active» Needs review
StatusFileSize
new1.86 KB
PASSED: [[SimpleTest]]: [MySQL] 34,467 pass(es).
[ View ]

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.

Status:Needs review» Reviewed & tested by the community

Looks good, thanks!

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

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

Status:Reviewed & tested by the community» Needs review
StatusFileSize
new1.8 KB

D7 version.

StatusFileSize
new1.8 KB
PASSED: [[SimpleTest]]: [MySQL] 37,886 pass(es).
[ View ]

Renamed for testing.

Status:Needs review» Needs work

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

StatusFileSize
new1.8 KB
PASSED: [[SimpleTest]]: [MySQL] 37,913 pass(es).
[ View ]

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

Status:Needs work» Needs review

Change status.

Status:Needs review» Reviewed & tested by the community

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

Status:Reviewed & tested by the community» Fixed

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

YAYYY! :D Welcome, Jennifer!!

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