Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

here is my code:

$nid = $entity->field_empf_number['und']['0']['nid'];  
$result = db_query("SELECT MAX(entity_id) FROM field_data_field_empf_number WHERE field_empf_number_nid = $nid")->fetchField();  
if (isset($result)){  
  $n = $result ;  
  $node = node_load($n);  
  $node->field_empf_stat['und']['0']['value'] = 'off';  //list field  
  node_save($node);  
}  
$entity_field[0]['value'] = $result;`

when add new node (if there is previous node i mean the if statement return true ) this error message show up:

Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\wamp\www\finance\includes\database\database.inc on line 429

I googled but i did not found any answers.

share|improve this question
2  
I guess you are calling this in one of the node hooks which will become infinite loop because of node_save in the code !! – Anil Sagar Oct 16 '12 at 11:50
are you telling me to write "node_Save" function out of the if statement? – abd Oct 16 '12 at 12:27
I mean where is above code written ?? – Anil Sagar Oct 16 '12 at 12:30
2  
What Anil means is that the computed field is probably computed when a node is saved. Since you save a node (again) the computed field is computed again, which causes a node to be saved, which causes the computed field to be saved, and so on, forever. – Letharion Oct 16 '12 at 13:15
but this problem caused when creating new node – abd Oct 16 '12 at 14:17

1 Answer

Try to change the node_save($node) to drupal_register_shutdown_function('node_save', $node). It will remove the old node saving process from the actual node saving. But I don't think, that type of code should have place within a computed field. The computed field good to modify the same field. It isn't designed for modifying other data of your system. These code should be in a custom module in hook_node_presave().

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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