EDITED: This has been altered to include the code suggested by Dooshta.
I need to fill a computed field with the average value of all entries in a certain field, and only from nodes that have a specific node reference field.
What I have right now in my Computed Field is:
$nids = db_query('
SELECT entity_id FROM {field_revision_field_venue_reference_review}
WHERE field_venue_reference_review_target_id = :nid',
array(':nid' => $entity->nid)
)->fetchCol();
$entity_field[0]['value'] = db_query('
SELECT AVG(field_payment_review_value) FROM {field_data_field_payment_review}
WHERE entity_id IN (:nids)',
array(':nids' => $nids)
)->fetchField();
This is working, and displays the correct average from the correct nodes. However, I get a PODexception error on some pages that do not include the above code. This is confusing to me, because it seems that if there is bad syntax, then I should get the error on the page using the code as well as pages not using the code, right? Either that or it just shouldn't work.
As requested by Booshta, here are screenshots of the tables I'm querying.
The first is the table containing the entity reference field in the $nids
part of the query
The second is the table containg the values being averaged in the $entity_field
part of the query