Hi, I have 3 content types Item, Reservation and Client.
Content type Item has node reference (field_node) to Reservation, and the nodes from Reservation has a node reference count field (field_count_count) that is counting the references from Item nodes to very single Reservation node.
Content type Reservation has a node reference (field_client_ref) to the node from Client corresponding to the particular client. On the content type Client I have a computed field that is supposed to sum all the reference count field values that are concerning every single client. I also installed Corresponding node references and set a back reference from Client to Reservation nodes.

Then I put the following php code in my computed field:

$client_id = $entity->field_data_field_client_ref[LANGUAGE_NONE][0]['nid'];
$client_node_id = node_load($client_id, NULL, TRUE);
$entity_field[0]['value'] = db_query("
SELECT SUM(field_count_count)
FROM field_data_field_count
WHERE entity_id = '$client_node_id';
")->fetchField();

But the system responses:
Notice: Undefined property: stdClass::$field_data_field_client_ref in eval() (line 1 of /home/teambill/public_html/drupal7/sites/all/modules/computed_field/computed_field.module(466) : eval()'d code).

Any suggestions or help, please!

Comments

razkovnik’s picture

Any help or suggestions for solving the problem will be highly appreciated!

tomrishworth’s picture

Did you ever find a solution for this? I'm trying to do something similar.

Thanks

razkovnik’s picture

Yes, I solved it using aggregation in Views. Just play around with grouping field, in a table style view, and aggregate the fields you want to sum.
Hope this will help you.

razkovnik’s picture

Status: Active » Closed (fixed)