I don't understand when a computed field computes. Does it compute when the fields it draws on are updated or when someone views the node it's used in?


From Computed Field Module:

Computed Field is a very powerful CCK field module that lets you add a custom "computed fields" to your content types. These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it. (Feeling the power yet? :) ) You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views. (Although you should note that Views use requires database stored values.) This field is literally the Swiss Army knife of CCK fields. So start cooking up your PHP based values!

In the documentation page ( http://drupal.org/node/126522 ) it also says:

When is the field actually computed?

If you wish to store the values in the database then you have to update or re-submit the node to compute the value of the field.

If it is not stored in the database then the value computes when the node loads and only when the node is loaded. The field will not work in views nor will it function properly if it depends on other non-stored computed fields.

More information from drupal.org and what appears to be a good page of snippets is http://drupal.org/node/149228

  • If save the fields on the database but need the computed fields to be recomputed when the node is loaded, without re-saving the node, use the computed field tools module (drupal.org/project/computed_field_tools). – Druvision Dec 19 '13 at 21:52

These days (more then 3 years after this question was asked), there is a NOT commonly known/used alternative available for the Computed Field module, i.e. the (fairly new) Math Field module (for D7). Some more details about this module (from its project page), which also details when the calculations actually happen:

The Math Field module defines a new field type to dynamically calculate values on entity forms. This is an alternative to Computed Field that does not require the use of PHP Filter.

Math expression fields are dynamically updated via ajax on the entity form as soon as all necessary fields are populated. If JavaScript is disabled, the field will be evaluated when the form is submitted. The result is stored in the database when the form is submitted.

For more details (step-by-step instructions), refer to either of these links:

Known issues

As this is a fairly new D7 module, there are still a few (known) issues with it, as mentioned also on its project page:

Bonus: you would not need the "PHP filter" (IMO only that should be a valid reason to investigate this alternative) ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.