Home > PHP > SugarCRM: check updating of object’s property

SugarCRM: check updating of object’s property

Sometimes it’s needed to know about updating of specified object’s property. SugarCRM keeps previous values for all object’s properties in the array fetched_row. For example, to realise it’s new object or just updated we should compare ID from that array and current value of object’s property:

  1. if($obj->fetched_row[‘id’] != $obj->id) {
  2.     echo "This’s a new object!\n";
  3. } else {
  4.     echo "This’s an existing object\n";
  5. }

That approach might be used in the handler of logic hook, for example, to perform some action when desire property is changed.

Categories: PHP Tags: ,
  1. Sergey
    July 31st, 2009 at 10:09 | #1

    That is the sign of just how bad SugarCRM orm still is. In Rails you’d check it with simple “record.new_record?” call, which is much more natural.

  2. July 31st, 2009 at 11:22 | #2

    It’s easy to create your own wrapper for SugarCRM as well :) I suspect nobody need it. Moreover, Rails is framework but Sugar – software product based on PHP :)

  1. No trackbacks yet.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes