adding all children node flag count to sort parent i have created two content type parent and child. a parent has children. and each child has own flag count value. like:

under Parent A
   child1 had flag count=5
   child2 had flag count=2
   child3 had flag count=0

under Parent B
    child1 had flag count=3
    child2 had flag count=1
    child3 had flag count=0
    child4 had flag count=6.

now sort the parent according to all children's flag count value.Like here Parent B should come first because he has his children flag count value is 10..

please help me to short out this scenario...
Is it possible to have a hidden field on parent node value for which updates as per the flag counter on referenced node changes.In that case it will be easier to build custom query or even if you use views you can sort by the hidden field  value.

Updated:


  
  Child node 1 has a node reference to Parent Node.
  Keep flag count as hidden field on parent content type
  The time flag is updated on Child node, you can grab all parent nodes on the updated child node.
  Change the hidden field value on parent node from hidden field value to +1.
  


Code that can be used to update parent node field
 - you will have all parent node id in child node object, grab the ids.
 - Use the following code to update the parent fields.

  $node = node_load($nid);
  $node-&gt;field_flag_count['und'][0]['value'] += 1;
  field_attach_presave('node', $node);
  field_attach_update('node', $node);



  This will save lot more node save processing and unnecessary node
  revisions


SO this way the total flag count will all be present on parent node and sorting will be lot more easier that way!.