API page: http://api.drupal.org/api/drupal/includes--entity.inc/function/EntityFie...
Dear all,
The documentation of 'Return Value' states:
$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
Comment | File | Size | Author |
---|---|---|---|
#9 | 1427098-d7-version-2.patch | 1.8 KB | chris.leversuch |
#7 | 1427098-d7-version.patch | 1.8 KB | chris.leversuch |
#6 | 1427098-d7.patch | 1.8 KB | chris.leversuch |
#3 | 1427098.patch | 1.86 KB | chris.leversuch |
Comments
Comment #1
jhodgdonThanks 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.
Comment #2
jhodgdonFor 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
Comment #3
chris.leversuch CreditAttribution: chris.leversuch commentedI'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.
Comment #4
jhodgdonLooks good, thanks!
Comment #5
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks. Moving to 7.x.
Comment #6
chris.leversuch CreditAttribution: chris.leversuch commentedD7 version.
Comment #7
chris.leversuch CreditAttribution: chris.leversuch commentedRenamed for testing.
Comment #8
jhodgdonThis patch is not the same as th D8 patch. It has a typo "In most this cases this...".
Comment #9
chris.leversuch CreditAttribution: chris.leversuch commentedI knew there was something else I fixed in the D8 version. This one should be correct.
Comment #10
chris.leversuch CreditAttribution: chris.leversuch commentedChange status.
Comment #11
jhodgdonThanks -- now the patches are the same (except context). :)
Comment #12
jhodgdonCommitted to 7.x. My first commit! :)
Comment #13
webchickYAYYY! :D Welcome, Jennifer!!